[英]Python NameError: name 'ridge_regression_sklearn' is not defined
[英]NameError: name 'Ridge' is not defined
我是初學者學習機器學習。 我正在使用IDLE spyder和此Python版本:
Python 3.4.3 |Anaconda 2.3.0 (64-bit)| (default, Mar 6 2015, 12:06:10) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
我遇到以下錯誤:
NameError: name 'Ridge' is not defined
您能幫我找出這段代碼有什么問題嗎? 這個問題與Python版本有關嗎?
from sklearn import linear_model
clf = linear_model.Ridge(alpha=.5)
clf.fit ([[0, 0], [0, 0], [1, 1]], [0, .1, 1])
Ridge(alpha=0.5, copy_X=True, fit_intercept=True, max_iter=None,
normalize=False, random_state=None, solver='auto', tol=0.001)
clf.coef_
提前致謝
請查看下面兩個代碼段之間的區別,第一個是正確的,第二個會產生錯誤:
首先 :
from sklearn import linear_model
clf = linear_model.Ridge (alpha = .5)
clf.fit([[0, 0], [0, 0], [1, 1]], [0, .1, 1])
clf.coef_
array([ 0.34545455, 0.34545455])
第二:
from sklearn import linear_model
clf = linear_model.Ridge (alpha = .5)
clf.fit ([[0, 0], [0, 0], [1, 1]], [0, .1, 1])
Ridge(alpha=0.5, copy_X=True, fit_intercept=True, max_iter=None,
normalize=False, random_state=None, solver='auto', tol=0.001)
clf.coef_
NameError: name 'Ridge' is not defined
編輯 :
您應該在Python解釋器中逐行運行第一個代碼段中的行(或者在Ipython筆記本中作為一個整體單元格運行),您將獲得該行
Ridge(alpha=0.5, copy_X=True, fit_intercept=True, max_iter=None,
normalize=False, random_state=None, solver='auto', tol=0.001)
在輸出已執行后clf.fit([[0, 0], [0, 0], [1, 1]], [0, .1, 1])
語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.