The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
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 라이브러리가 설치되어 있는지 어떻게 확인합니까?
내 환경에서는 작동하지 않아서 구성 문제인 것 같습니다.
설정방법을 알려주시면 정말 감사하겠습니다.