Why I get the X_train_std is not defined

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vokoyo
    New Member
    • Apr 2018
    • 7

    Why I get the X_train_std is not defined

    May I know why I get the error message -

    NameError: name 'X_train_std' is not defined






    Code:
    from sklearn.linear_model import LogisticRegression
    
    lr = LogisticRegression(C=1000.0, random_state=0)
    lr.fit(X_train_std, y_train)
     
    plot_decision_regions(X_combined_std,
                          y_combined, classifier=lr,
                          test_idx=range(105,150))
    
    plt.xlabel('petal length [standardized]')
    plt.ylabel('petal width [standardized]')
    plt.legend(loc='upper left')
    plt.tight_layout()
    
    plt.show()
     
    lr.predict_proba(X_test_std[0,:])
    
    weights, params = [], []
    for c in np.arange(-5, 5):
        lr = LogisticRegression(C=10**c, random_state=0)
        lr.fit(X_train_std, y_train)
        weights.append(lr.coef_[1])
        params.append(10**c)
    weights = np.array(weights)
    plt.plot(params, weights[:, 0],
             label='petal length')
    plt.plot(params, weights[:, 1], linestyle='--',
             label='petal width')
    plt.ylabel('weight coefficient')
    plt.xlabel('C')
    plt.legend(loc='upper left')
    plt.xscale('log')
    plt.show()
    Attached Files
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Where do you define it?

    Comment

    • vokoyo
      New Member
      • Apr 2018
      • 7

      #3




      Look carefully -





      from sklearn.model_s election import train_test_spli t






      Comment

      Working...