- from sklearn.ensemble import RandomForestClassifier
- from sklearn.metrics import accuracy_score
- # Load train and test data for classification
- train_data = pd.read_excel('your_file.xlsx', sheet_name='Train set - Classification')
- test_data = pd.read_excel('your_file.xlsx', sheet_name='Test set - Classification')
- # Separate features (X) and target variable (y)
- X_train_cls = train_data.drop(columns=['price_range'])
- y_train_cls = train_data['price_range']
- X_test_cls = test_data.drop(columns=['price_range'])
- y_test_cls = test_data['price_range']
- # Train the classifier
- classifier = RandomForestClassifier(n_estimators=100, random_state=42)
- classifier.fit(X_train_cls, y_train_cls)
- # Predict on the test set
- y_pred_cls = classifier.predict(X_test_cls)
- # Evaluate the classifier
- accuracy = accuracy_score(y_test_cls, y_pred_cls)
- print("Accuracy:", accuracy)
[text] J
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
Editor
You can edit this paste and save as new: