๐ŸŽ‰Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

Execute Python - 192 Error

User: "YunJeong_Kang"
New Altair Community Member
Updated by Jocelyn
I want to ues python cord in rapidminer.
So, I would like to conduct a test using the dataset in sklearn.
However, I confirmed that an error occurred in the code that loaded the dataset.
Is there anything I need to configure to use python's sklearn?

I will tell you the code I wrote and the error message.


-Erroe meggage - 
Execution of Python script failed

The execution of the python script failed.
Please check your Python script:KeyError: 192
(script, line11)

- Python Cord -
import matplotlib.pyplot as plt
import pandas as pd

from sklearn import datasets
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, r2_score


def rm_main():
house = datasets.fetch_california_housing()
X = house.data
y = house.target

X_train, X_test, y_train, y_test = train_test_split(house.data, house.target, test_size = 0.2)
estimator = RandomForestRegressor(n_estimators=100)

estimator.fit(X_train, y_train)

prediction = estimator.predict(X_test)

mse = mean_squared_error(y_test, prediction)
r_squared = r2_score(y_test, prediction)
print(f"MSE: {mse}")
print(f"R-squared: {r_squared}")

if __name__ == "__main__":
main()


line11 : house = datasets.fetch_california_housing()

Find more posts tagged with

Sort by:
1 - 1 of 11
    User: "Caperez"
    Altair Community Member
    Accepted Answer
    Hi @YunJeong_Kang,
    Please check that you have installed the sci-kit library in your Anaconda or Python environment configured in RM, this is probably the main reason. 

    Also be careful with indentation, the Rapidminer Python operator is very sensitive to this.

    Finally, I ran your script in my environment with scikit and it works. 

    See below for a simple example. 

    Best, 

    import pandas
    import matplotlib.pyplot as plt
    import pandas as pd

    from sklearn import datasets
    from sklearn.ensemble import RandomForestRegressor
    from sklearn.model_selection import train_test_split
    from sklearn.metrics import mean_squared_error, r2_score


    def rm_main():
    house = datasets.fetch_california_housing()
    X = house.data
    y = house.target

    X_train, X_test, y_train, y_test = train_test_split(house.data, house.target, test_size = 0.2)
    estimator = RandomForestRegressor(n_estimators=100)
    estimator.fit(X_train, y_train)
    prediction = estimator.predict(X_test)
    mse = mean_squared_error(y_test, prediction)
    r_squared = r2_score(y_test, prediction)
    print(f"MSE: {mse}")
    print(f"R-squared: {r_squared}")
    df = pd.DataFrame(prediction)

    return(df)