434,905 Members | 2,083 Online
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

# Why I get the X_train_std is not defined

P: 7
May I know why I get the error message -

NameError: name 'X_train_std' is not defined

Expand|Select|Wrap|Line Numbers
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.
Attached Images
 Logistic regression.jpg (57.8 KB, 21 views)
Attached Files
 Logistic regression.pdf (291.6 KB, 32 views)
Mar 18 '19 #1