为什么没有定义X_train_std

我可以知道为什么我收到错误消息-
NameError:未定义名称'X_TRAIN_STD'

选择 | 换行 | 行号
  1.  
  2. from sklearn.linear_model import LogisticRegression
  3.  
  4. lr = LogisticRegression(C=1000.0, random_state=0)
  5. lr.fit(X_train_std, y_train)
  6.  
  7. plot_decision_regions(X_combined_std,
  8.                       y_combined, classifier=lr,
  9.                       test_idx=range(105,150))
  10.  
  11. plt.xlabel('petal length [standardized]')
  12. plt.ylabel('petal width [standardized]')
  13. plt.legend(loc='upper left')
  14. plt.tight_layout()
  15.  
  16. plt.show()
  17.  
  18. lr.predict_proba(X_test_std[0,:])
  19.  
  20. weights, params = [], []
  21. for c in np.arange(-5, 5):
  22.     lr = LogisticRegression(C=10**c, random_state=0)
  23.     lr.fit(X_train_std, y_train)
  24.     weights.append(lr.coef_[1])
  25.     params.append(10**c)
  26. weights = np.array(weights)
  27. plt.plot(params, weights[:, 0],
  28.          label='petal length')
  29. plt.plot(params, weights[:, 1], linestyle='--',
  30.          label='petal width')
  31. plt.ylabel('weight coefficient')
  32. plt.xlabel('C')
  33. plt.legend(loc='upper left')
  34. plt.xscale('log')
  35. plt.show()
  36.  

附加图像
File Type: jpg
Logistic Regression.jpg
(57.8KB,119次浏览)
附加的文件
File Type: pdf
逻辑回归.pdf
(291.6 KB,82次浏览)

# 回答1


你在哪里定义它?
# 回答2


仔细看-
从sklearn.模型选择导入培训_测试_拆分

标签: python

添加新评论