antitheft159 commited on
Commit
108e0c0
1 Parent(s): 5e79b1e

Upload skipwithpredictor_159.py

Browse files
Files changed (1) hide show
  1. skipwithpredictor_159.py +114 -0
skipwithpredictor_159.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """skipwithpredictor.159
3
+
4
+ Automatically generated by Colab.
5
+
6
+ Original file is located at
7
+ https://colab.research.google.com/drive/1C7AO89jheeQ3C61BPsSdIfK5tCgcL7IT
8
+ """
9
+
10
+ import pandas as pd
11
+ import numpy as np
12
+
13
+ df = pd.read_csv('/content/online_course_engagement_data.csv')
14
+
15
+ df.dtypes
16
+
17
+ df.info()
18
+
19
+ df.isnull().sum()
20
+
21
+ df.drop('UserID', axis=1,inplace=True)
22
+
23
+ df['CourseCategory'].unique()
24
+
25
+ cat_mapping={
26
+ 'Heatlh': 1,
27
+ 'Arts': 2,
28
+ 'Science': 3,
29
+ 'Programming': 4,
30
+ 'Business': 5
31
+ }
32
+
33
+ df['CourseCategory'] = df['CourseCategory'].map(cat_mapping)
34
+
35
+ from sklearn.preprocessing import StandardScaler
36
+ scaler = StandardScaler()
37
+
38
+ df['QuizScores'] = scaler.fit_transform(df[['QuizScores']])
39
+ df['CompletionRate'] = scaler.fit_transform(df[['CompletionRate']])
40
+
41
+ df.head(15)
42
+
43
+ df.dtypes
44
+
45
+ import matplotlib.pyplot as plt
46
+ import seaborn as sns
47
+
48
+ int_col = df.select_dtypes(include='int').columns
49
+ float_col = df.select_dtypes(include='float').columns
50
+
51
+ plt.figure(figsize=(15,15))
52
+
53
+ for i, col in enumerate(int_col, 1):
54
+ plt.subplot(3,2,i)
55
+ counts = df[col].value_counts()
56
+ plt.bar(counts.index, counts)
57
+ plt.title(f'Bar Chart of {col}')
58
+ plt.xlabel(col)
59
+ plt.ylabel('Frequency')
60
+
61
+ for x, y in zip(counts.index, counts):
62
+ plt.text(x, y, str(y), ha='center', va='bottom')
63
+
64
+ plt.tight_layout()
65
+ plt.show
66
+
67
+ plt.figure(figsize=(12, 6))
68
+
69
+ for i, col in enumerate(float_col, 1):
70
+ plt.subplot(1, 3, 1)
71
+ sns.boxplot(y=df[col])
72
+ plt.title(f'Box Plot of {col}')
73
+ plt.ylabel(col)
74
+
75
+ plt.tight_layout()
76
+ plt.show()
77
+
78
+ cor = df.corr()
79
+
80
+ plt.figure(figsize=(10, 6))
81
+ sns.heatmap(cor,annot=True, cmap="coolwarm", fmt=".2f")
82
+
83
+ from sklearn.model_selection import train_test_split
84
+ from sklearn.ensemble import RandomForestClassifier
85
+ import xgboost as xgb
86
+ import lightgbm as lgb
87
+ from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
88
+
89
+ X = df.drop('CourseCompletion', axis=1)
90
+ y = df['CourseCompletion']
91
+
92
+ seed = 42
93
+
94
+ Xtrain, Xtest, ytrain, ytest = train_test_split(X, y, test_size=0.2, random_state=seed)
95
+
96
+ models = {
97
+ 'RandomForest': RandomForestClassifier(random_state=seed),
98
+ 'XGBoost': xgb.XGBClassifier(random_state=seed),
99
+ 'LightGBM': lgb.LGBMClassifier(random_state=seed)
100
+ }
101
+
102
+ result = {}
103
+
104
+ for name, model in models.items():
105
+ model.fit(Xtrain, ytrain)
106
+ y_pred = model.predict(Xtest)
107
+ accuracy = accuracy_score(ytest, y_pred)
108
+ result[name] = accuracy
109
+ print(f'{name} Accuracy: {accuracy:.2f}')
110
+
111
+ print('Classification Report:')
112
+ print(classification_report(ytest, y_pred))
113
+ print('Confusion Matrix:')
114
+ print(confusion_matrix(ytest, y_pred))