[text] M

Viewer

  1. import pandas as pd
  2. from sklearn.ensemble import RandomForestClassifier
  3. from sklearn.model_selection import cross_val_score
  4.  
  5. # Load train data for classification
  6. train_data = pd.read_excel('your_file.xlsx', sheet_name='Train set - Classification')
  7.  
  8. # Separate features (X) and target variable (y) from the training data
  9. X_train_cls = train_data.drop(columns=['price_range'])
  10. y_train_cls = train_data['price_range']
  11.  
  12. # Train the classifier using cross-validation
  13. classifier = RandomForestClassifier(n_estimators=100, random_state=42)
  14. accuracy_scores = cross_val_score(classifier, X_train_cls, y_train_cls, cv=5)  # 5-fold cross-validation
  15.  
  16. # Calculate mean accuracy
  17. mean_accuracy = accuracy_scores.mean()
  18. print("Mean Accuracy:", mean_accuracy)

Editor

You can edit this paste and save as new:


File Description
  • M
  • Paste Code
  • 27 Apr-2024
  • 759 Bytes
You can Share it: