You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[5], line 6
3 from lux.pyuid3.data import Data
4 data = Data.parse_dataframe(test[features+[target]])
----> 6 predictions = [int(x.get_name()) for x in lux.uid3.predict(data.instances)]
7 print(f'Accuracy : {accuracy_score(predictions, test[target])}')
File ~/Software/lux/src/lux/pyuid3/uid3.py:554, in UId3.predict(self, X)
552 def predict(self, X: pd.DataFrame):
553 predictions = []
--> 554 for instance in X.to_numpy():
555 att_stats = self.tree.predict(instance, list(X.columns))
556 predictions.append(att_stats.get_most_probable())
AttributeError: 'numpy.ndarray' object has no attribute 'to_numpy'
Code to reproduce:
fromlux.luximportLUXfromsklearnimportdatasetsfromsklearn.model_selectionimporttrain_test_splitimportnumpyasnpimportpandasaspdfrommatplotlibimportpyplotaspltimportseabornassnsfromsklearn.ensembleimportRandomForestClassifierwine=datasets.load_wine()
features= [f.replace('/','_') forfinwine['feature_names']]
target='class'rs=42fraction=0.1#create daatframe with columns names as strings (LUX accepts only DataFrames with string columns names)df_wine=pd.DataFrame(wine.data,columns=features)
df_wine[target] =wine.target#train classifiertrain, test=train_test_split(df_wine, random_state=rs)
clf=RandomForestClassifier(random_state=42)#svm.SVC(probability=True, random_state=rs)clf.fit(train[features],train[target])
clf.score(test[features],test[target])
## Without predictor uncertainty#pick some instance from datasetri2e=train[features].sample(1, random_state=42).valuesi2e#train lux on neighbourhood equal 30% instanceslux=LUX(predict_proba=lambdax: np.round(clf.predict_proba(x)), neighborhood_size=int(len(train)*fraction),max_depth=2, node_size_limit=1, grow_confidence_threshold=0 )
lux.fit(train[features], train[target], instance_to_explain=i2e,class_names=[0,1,2])
#see the justification of the instance being classified for a given classlux.justify(np.array(i2e))
#calculate decision tree score over this datasetfromsklearn.metricsimportaccuracy_score, f1_score, precision_score, recall_scorefromlux.pyuid3.dataimportDatadata=Data.parse_dataframe(test[features+[target]])
predictions= [int(x.get_name()) forxinlux.uid3.predict(data.instances)]
print(f'Accuracy : {accuracy_score(predictions, test[target])}')
The text was updated successfully, but these errors were encountered:
Code to reproduce:
The text was updated successfully, but these errors were encountered: