Sure! Here are some pieces of code that you could use to get started on your project:
- Import necessary libraries:
import pandas as pd
import numpy as np
from sklearn.datasets import load_boston
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix, accuracy_score, precision_score, recall_score, f1_score
from sklearn.ensemble import RandomForestClassifier
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt
- Load the Boston Housing dataset and split it into training and testing sets:
train_df, test_df = load_boston()
X = train_df.drop("Sale", axis=1)
y = train_df["GoingUp"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
- Train a logistic regression model on the training data and make predictions on the test data:
lr = LogisticRegression()
lr.fit(X_train, y_train)
y_pred = lr.predict(X_test)
conf_mat = confusion_matrix(y_test, y_pred)
accuracy = accuracy_score(y_test, y_pred)
precision = precision_score(y_test, y_pred)
recall = recall_score(y_test, y_pred)
f1 = f1_score(y_test, y_pred)
plt.imshow(conf_mat, cmap='viridis')
plt.colorbar()
plt.show()
print("Accuracy:", accuracy)
print("Precision:", precision)
print("Recall:", recall)
print("F1 Score:", f1)
- Train a random forest classifier on the training data and make predictions on the test data:
rf = RandomForestClass