- import pandas as pd
- from sklearn.ensemble import RandomForestClassifier
- from sklearn.model_selection import cross_val_score
- # Load train data for classification
- train_data = pd.read_excel('your_file.xlsx', sheet_name='Train set - Classification')
- # Separate features (X) and target variable (y) from the training data
- X_train_cls = train_data.drop(columns=['price_range'])
- y_train_cls = train_data['price_range']
- # Train the classifier using cross-validation
- classifier = RandomForestClassifier(n_estimators=100, random_state=42)
- accuracy_scores = cross_val_score(classifier, X_train_cls, y_train_cls, cv=5) # 5-fold cross-validation
- # Calculate mean accuracy
- mean_accuracy = accuracy_scores.mean()
- print("Mean Accuracy:", mean_accuracy)
[text] M
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:
File Description
- M
- Paste Code
- 27 Apr-2024
- 759 Bytes
You can Share it:
Latest Code Pastes