def train(self, train_data): _. y_train, features = train_ data. iloc[:, :-1], train data. iloc[:,-1], train data.colums[:-1]
时间: 2024-01-18 15:02:10 浏览: 90
Numpy及Pandas_numpy_pandas_dataframe_python_
# Splitting the data into training and validation sets
X_train, X_val, y_train, y_val = train_test_split(features, y_train, test_size=0.2, random_state=42)
# Training the model
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)
# Evaluating the model on the validation set
y_pred = model.predict(X_val)
accuracy = accuracy_score(y_val, y_pred)
print("Accuracy:", accuracy)
阅读全文