Итак, я пытаюсь использовать Extra Tree Classifier, чтобы найти значение параметра в моем наборе данных, но по какой-то причине каждый раз, когда я запускаю код, он говорит мне, что количество меток не соответствует количеству выборок, и я действительно не знаю, как это исправить, у моего набора данных нет нанов, нулей или пустых ячеек. Он состоит из 13 столбцов, все из которых имеют одинаковое количество строк.
Код:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
from sklearn.ensemble import ExtraTreesClassifier
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
# Loading First Dataframe
link = '............'
fluff, id = link.split('=')
print (id) # Verify that you have everything after '='
downloaded = drive.CreateFile({'id':id})
downloaded.GetContentFile('Final After Simple Filtering.csv')
df = pd.read_csv('Final After Simple Filtering.csv',index_col=None,low_memory=True)
df = df.astype(float)
ExtraT = ExtraTreesClassifier(n_estimators =250,random_state=0,bootstrap=False,min_weight_fraction_leaf=0.4)
y=df['Power_kW']
df=df.drop(df['Power_kW'])
X=df
ExtraT.fit(X,y)
feature_importance = ExtraT.feature_importances_
feature_importance_normalized = np.std([tree.feature_importances_ for tree in ExtraT.estimators_], axis = 1)
plt.bar(X.columns, feature_importance)
plt.xlabel('Lable')
plt.ylabel('Feature Importance')
plt.title('Parameters Importance')
plt.show()
Ошибка:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-10-a213399da605> in <module>()
48 #y= df.iloc[:, 0]
49
---> 50 ExtraT.fit(X,y)
51
52 feature_importance = ExtraT.feature_importances_
10 frames
/usr/local/lib/python3.6/dist-packages/sklearn/tree/_classes.py in fit(self, X, y, sample_weight, check_input, X_idx_sorted)
263 if len(y) != n_samples:
264 raise ValueError("Number of labels=%d does not match "
--> 265 "number of samples=%d" % (len(y), n_samples))
266 if not 0 <= self.min_weight_fraction_leaf <= 0.5:
267 raise ValueError("min_weight_fraction_leaf must in [0, 0.5]")
ValueError: Number of labels=10049972 does not match number of samples=10043104
Спасибо.