mljar / mljar-examples

Examples how MLJAR can be used
Apache License 2.0
58 stars 33 forks source link

typo in example code. #4

Closed partrita closed 3 years ago

partrita commented 3 years ago

For example, in regression example AttributeError was occured.

from sklearn.model_selection import train_test_split
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from supervised.automl import AutoML # mljar-supervised

X = df3[['HC/LC', 'Residue', 'MutationSite']]
y = df3['Conc.(mg/mL)']
X_train, X_test, y_train, y_test = train_test_split(X, y,
    test_size=0.25, random_state=42,
)

# train models with AutoML
automl = AutoML(mode="Explain")
automl.fit(X_train, y_train)

# compute the MSE on test data
predictions = automl.predict(X_test)
print(predictions.head())
print("Test MSE:", mean_squared_error(y_test, predictions["prediction"]))
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-fa1faad68f15> in <module>
     17 # compute the MSE on test data
     18 predictions = automl.predict(X_test)
---> 19 print(predictions.head())
     20 print("Test MSE:", mean_squared_error(y_test, predictions["prediction"]))

AttributeError: 'numpy.ndarray' object has no attribute 'head'

automl.predict function return numpy array. I guess automl.predict_all is a suitable function.

predictions = automl.predict_all(X_test)
print(predictions.head())
pplonski commented 3 years ago

@partrita do you know how to fix it? Can you do PR for it? Can you tell me in which file there is a typo?

pplonski commented 3 years ago

It should be:

predictions = automl.predict(X_test)
print("Test MSE:", mean_squared_error(y_test, predictions))