-2

I try to use correlation to extract features , but I faced this problem: please help me, how I can fix it?

AttributeError: module 'numpy' has no attribute 'corroef'

This my code to correlate the features::

    cor_list = []
    feature_name = X_train[0]
    print(feature_name)
    #calculate the correlation with y for each feature
    for i in feature_name:
        cor = np.corroef(X_train[i], y_train)[0, 1]
        cor_list.append(cor)
     #replace NaN with 0
    cor_list = [0 if np.isnan(i) else i for i in cor_list]
    #feature_name
    cor_feature = X_train.iloc[:np.argsort(np.abs(cor_list))[-num_feats:]].columns.tolist()
    return cor_feature ```


Roaa
  • 23
  • 1
  • 7

1 Answers1

1

You have misspelled corrcoef... This is the syntax:

numpy.corrcoef(x, y=None, rowvar=True, bias=<no value>, ddof=<no value>, *, dtype=None)
SANGEETH SUBRAMONIAM
  • 1,098
  • 1
  • 9
  • 10
  • This deserves to be a **comment** (and it already is) rather than an answer ... – donkopotamus Mar 11 '21 at 00:03
  • I dont know how this works . but if that how that is, then understood !1 – SANGEETH SUBRAMONIAM Mar 11 '21 at 00:06
  • Thank you I fix the misspellted, but appear another problem In this line: `cor = np.corrcoef(X_train[i], y_train)[0, 1]` IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices – Roaa Mar 11 '21 at 04:05
  • Looks like you are not properly indexing the numpy array. print out the values of the index and check if they are proper – SANGEETH SUBRAMONIAM Mar 11 '21 at 04:23