Due to recent updates, all users are required to create an Altair One account to login to the RapidMiner community. Click the Register button to create your account using the same email that you have previously used to login to the RapidMiner community. This will ensure that any previously created content will be synced to your Altair One account. Once you login, you will be asked to provide a username that identifies you to other Community users. Email us at Community with questions.
Execute Python - 192 Error
YunJeong_Kang
Member Posts: 7 Learner I
in Help
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
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 -
line11 : house = datasets.fetch_california_housing()
- 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()
0
Best Answer
-
ceaperez Member Posts: 541 UnicornHi @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)
0
Answers
RM에 구성된 Python 환경에 sklearn 라이브러리가 설치되어 있는지 어떻게 확인합니까?
내 환경에서는 작동하지 않아서 구성 문제인 것 같습니다.
설정방법을 알려주시면 정말 감사하겠습니다.