write python program using ada boost algorithm generate csv files from this code: import…
- User
write python program using ada boost algorithm
generate csv files from this code:
import pandas as pd from sklearn.datasets import make_classification from sklearn.model_selection import train_test_split from sklearn.ensemble import AdaBoostClassifier from sklearn.metrics import accuracy_score
Define the number of samples
n_samples = 1000
Generate a synthetic dataset
X, y = make_classification(n_samples=n_samples, n_features=10, n_informative=5, n_redundant=5, random_state=42, flip_y=0.03)
Feature names
features = ["CreditScore", "Geography", "Gender", "Age", "Tenure", "Balance", "NumOfProducts", "HasCrCard", "IsActiveMember", "EstimatedSalary"]
Convert into a DataFrame
df = pd.DataFrame(X, columns=features) df["ExitStatus"] = y
Let's take a quick look at the dataset
print(df.head())
Split data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(df[features], df["ExitStatus"], test_size=0.2, random_state=42)
Save the full dataset
df.to_csv('synthetic_employee_data.csv', index=False)
Optionally, you can also save the training and testing sets separately if needed
X_train.join(y_train).to_csv('training_data.csv', index=False) X_test.join(y_test).to_csv('testing_data.csv', index=False)
print("Data saved successfully.")
write python program and add below features with all plots outputs
Predicting on the test set
Probability estimates for ROC curve
Calculate accuracy, precision, and F1-score
Show classification report
Confusion matrix with plots
plt.figure(figsize=(6, 5)) cm = confusion_matrix(y_test, y_pred) sns.heatmap(cm, annot=True, fmt='d', cmap='Blues') plt.title('Confusion Matrix') plt.xlabel('Predicted') plt.ylabel('Actual') plt.show()
ROC curve
fpr, tpr, _ = roc_curve(y_test, y_score) roc_auc = roc_auc_score(y_test, y_score) plt.figure() plt.plot(fpr, tpr, color='darkorange', lw=2, label=f'ROC curve (area = {roc_auc:.2f})') plt.plot([0, 1], [0, 1], color='navy', lw=2, linestyle=":") plt.xlim([0.0, 1.0]) plt.ylim([0.0, 1.05]) plt.xlabel('False Positive Rate') plt.ylabel('True Positive Rate') plt.title('Receiver Operating Characteristic') plt.legend(loc="lower right") plt.show()
Visualize feature correlations
plt.figure(figsize=(10, 8)) corr = X_train.corr() sns.heatmap(corr, cmap='coolwarm', annot=True) plt.title('Feature Correlation Matrix') plt.show()
Density plot of feature values by class
code - Assistant
- User
- Assistant
- User
import pandas as pd from sklearn.datasets import make_classification from sklearn.model_selection import train_test_split from sklearn.ensemble import AdaBoostClassifier from sklearn.metrics import accuracy_score, precision_score, f1_score, classification_report, confusion_matrix, roc_curve, roc_auc_score import matplotlib.pyplot as plt import seaborn as sns
i have csv files synthetic_employee_data.csv training_data.csv testing_data.csv
- Assistant