Skip to content

Commit 525ac04

Browse files
committed
welcome
1 parent 0b75b50 commit 525ac04

File tree

3 files changed

+385
-1
lines changed

3 files changed

+385
-1
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
age,study_hours_per_week,attendance_rate,number_of_courses,assignments_completed,test_scores,passed
2+
24,12,69.58247563,5,9,58,0
3+
21,18,65.79579488,7,6,73,0
4+
22,27,79.57811041,1,9,84,1
5+
24,25,99.42601816,3,4,98,1
6+
20,20,69.68221086,2,9,84,0
7+
22,22,86.8854219,1,4,97,0
8+
22,28,90.46478461,2,6,85,1
9+
24,30,69.50550176,7,8,67,1
10+
19,29,89.12865394,6,4,98,0
11+
20,33,74.71132531,2,0,88,0
12+
24,19,85.29223322,3,9,81,1
13+
20,5,85.34118843,6,9,73,0
14+
20,29,81.43098736,2,0,72,0
15+
22,11,63.6115908,7,1,81,0
16+
21,13,93.41209982,6,5,86,1
17+
20,28,72.8312026,7,8,61,1
18+
23,5,67.46074042,2,7,98,1
19+
22,12,61.63100566,7,4,62,1
20+
19,28,83.63571773,3,0,72,1
21+
21,15,87.10257447,2,6,74,1
22+
23,21,60.66351316,2,4,84,1
23+
23,12,80.48372233,2,5,90,0
24+
19,39,69.05983101,1,6,79,0
25+
21,39,85.80691162,1,2,66,0
26+
22,37,66.97465716,1,9,98,0
27+
18,9,87.63750952,3,2,69,0
28+
21,32,75.46941385,6,4,97,0
29+
19,11,97.46919955,7,5,74,0
30+
23,13,65.50083777,5,8,71,1
31+
22,12,73.64265404,2,4,62,1
32+
21,16,64.53894085,7,0,68,0
33+
18,38,96.98774473,2,3,98,0
34+
18,37,95.09357414,3,4,85,1
35+
20,27,70.31766511,2,9,61,0
36+
20,28,86.39936184,1,9,90,0
37+
24,39,92.68888801,5,4,68,1
38+
19,26,82.20803246,4,6,61,0
39+
21,31,81.18602313,2,3,58,1
40+
21,39,69.67409164,7,0,56,0
41+
24,5,63.72411071,1,4,77,1
42+
23,39,95.88863032,4,6,63,1
43+
23,18,96.01672229,5,9,80,1
44+
24,7,85.32405829,4,9,68,0
45+
23,5,73.56119164,1,5,96,1
46+
20,9,73.96838298,6,4,65,0
47+
21,30,89.03822715,6,3,54,0
48+
24,18,95.8844104,4,1,84,0
49+
21,31,95.48345697,3,3,61,0
50+
18,13,91.19502183,7,9,74,1
51+
20,19,85.68126585,7,9,70,1
52+
22,19,63.3655986,4,2,85,0
53+
20,30,66.46514856,2,9,72,0
54+
24,17,95.94216754,2,0,65,1
55+
22,36,84.25716239,7,7,88,0
56+
18,36,60.36788206,7,4,94,1
57+
24,8,64.05886171,6,3,91,0
58+
19,34,86.54007076,3,7,88,0
59+
21,27,60.20246335,1,6,63,1
60+
18,19,66.43232206,2,1,80,0
61+
21,33,81.94935157,7,0,54,1
62+
23,17,87.67580791,6,3,84,0
63+
19,36,86.07845038,5,7,72,0
64+
19,11,68.97077238,6,1,78,0
65+
18,26,88.48716885,2,2,92,1
66+
19,32,69.4899635,2,0,60,0
67+
22,6,73.01598793,6,0,67,0
68+
19,10,89.8596562,1,2,96,0
69+
21,32,85.98531596,4,4,61,0
70+
21,32,93.96893642,2,2,58,1
71+
24,24,86.30451569,6,0,59,1
72+
21,34,82.73234413,7,0,93,0
73+
24,15,63.74699071,6,7,66,1
74+
21,32,74.70863212,3,9,87,0
75+
22,29,70.60809471,4,1,56,0
76+
24,37,69.75958574,5,2,95,0
77+
20,5,98.92042219,1,1,62,1
78+
23,31,75.72390899,5,2,89,1
79+
18,17,95.68186221,4,6,91,1
80+
21,7,85.24554504,4,0,58,1
81+
19,10,91.79245214,4,9,99,1
82+
21,12,80.10548372,5,7,76,1
83+
19,31,83.07615539,7,9,51,1
84+
23,13,79.70070775,4,9,54,1
85+
23,37,67.80971951,6,9,78,1
86+
23,28,88.89808461,5,1,86,0
87+
19,19,71.2308945,4,2,87,1
88+
21,36,60.97263866,6,8,68,1
89+
23,36,85.81889184,7,6,57,1
90+
22,28,67.08442718,3,3,97,1
91+
24,16,97.61834337,7,9,94,1
92+
19,6,98.15714308,4,4,50,1
93+
19,7,96.59457561,5,1,71,1
94+
21,21,74.80634801,2,7,66,1
95+
19,6,60.61826466,4,3,56,1
96+
19,6,97.1327425,2,8,74,1
97+
23,32,77.12736593,6,4,94,1
98+
21,27,98.66619276,3,8,53,0
99+
23,36,98.54479908,1,3,85,0
100+
24,37,94.12037822,7,9,55,1
101+
24,5,71.77795568,3,4,80,1

core/chapters/c11_Sklearn.py

Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,289 @@ def program(self):
518518

519519

520520

521+
class PracticeSklearn(Page):
522+
title = "Practice: Train your own model"
523+
524+
class loadDataset(VerbatimStep):
525+
"""
526+
Now it is time to practice what you just learned with a new dataset.
527+
The dataset has been adjusted to reflect a scenario involving students who either pass or fail a test.
528+
The features include age, study hours per week, attendance rate, number of courses taken, assignments completed, test scores, and a target variable indicating whether a student passed the test.
529+
Load the dataset and print the first few lines to get an impression.
530+
To directly apply your knowledge, replace the “?” with the correct code.
531+
532+
__copyable__
533+
import numpy as np
534+
import pandas as pd
535+
from sklearn.model_selection import train_test_split
536+
from sklearn.preprocessing import StandardScaler
537+
from sklearn.ensemble import RandomForestClassifier
538+
from sklearn.metrics import accuracy_score
539+
from sklearn.model_selection import cross_val_score
540+
from sklearn.model_selection import GridSearchCV
541+
import pyodide_http
542+
543+
pyodide_http.patch_all() # Necessary for downloading
544+
545+
# Load data using pandas
546+
data = pd.read_csv('https://raw.githubusercontent.com/aoberm/futurecoder/master/Datasets/Customer.csv')
547+
548+
# Print the first few lines
549+
print(data.?())
550+
"""
551+
552+
requirements = "hints"
553+
hints = """ test """
554+
555+
def program(self):
556+
import numpy as np
557+
import pandas as pd
558+
from sklearn.model_selection import train_test_split
559+
from sklearn.preprocessing import StandardScaler
560+
from sklearn.ensemble import RandomForestClassifier
561+
from sklearn.metrics import accuracy_score
562+
from sklearn.model_selection import cross_val_score
563+
from sklearn.model_selection import GridSearchCV
564+
import pyodide_http
565+
566+
pyodide_http.patch_all() # Necessary for downloading
567+
568+
# Load data using pandas
569+
data = pd.read_csv('https://raw.githubusercontent.com/aoberm/futurecoder/master/Datasets/Customer.csv')
570+
571+
# Print the first few lines
572+
print(data.head())
573+
574+
program_in_text = False
575+
576+
class TrainModel(VerbatimStep):
577+
"""
578+
Separate features and target variable (here: variable "passed", which indicates whether a student passed the test).
579+
Split your data into training and test sets using train_test_split. Use 80% of the data as training data.
580+
To directly apply your knowledge, replace the “?” with the correct code.
581+
582+
__copyable__
583+
import numpy as np
584+
import pandas as pd
585+
from sklearn.model_selection import train_test_split
586+
from sklearn.preprocessing import StandardScaler
587+
from sklearn.ensemble import RandomForestClassifier
588+
from sklearn.metrics import accuracy_score
589+
from sklearn.model_selection import cross_val_score
590+
from sklearn.model_selection import GridSearchCV
591+
import pyodide_http
592+
593+
pyodide_http.patch_all() # Necessary for downloading
594+
595+
# Load data using pandas
596+
data = pd.read_csv('https://raw.githubusercontent.com/aoberm/futurecoder/master/Datasets/Customer.csv')
597+
598+
# Separate features and target variable
599+
X = data.drop(?, axis=1)
600+
y = data[?]
601+
602+
# Splitting the data into training and testing sets
603+
X_train, X_test, y_train, y_test = train_test_split(?, ?, test_size=?, random_state=42)
604+
605+
"""
606+
607+
requirements = "hints"
608+
hints = """ test """
609+
610+
def program(self):
611+
import numpy as np
612+
import pandas as pd
613+
from sklearn.model_selection import train_test_split
614+
from sklearn.preprocessing import StandardScaler
615+
from sklearn.ensemble import RandomForestClassifier
616+
from sklearn.metrics import accuracy_score
617+
from sklearn.model_selection import cross_val_score
618+
from sklearn.model_selection import GridSearchCV
619+
import pyodide_http
620+
621+
pyodide_http.patch_all() # Necessary for downloading
622+
623+
# Load data using pandas
624+
data = pd.read_csv('https://raw.githubusercontent.com/aoberm/futurecoder/master/Datasets/Customer.csv')
625+
626+
# Separate features and target variable
627+
X = data.drop('Change', axis=1)
628+
y = data['Change']
629+
630+
# Splitting the data into training and testing sets
631+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
632+
633+
program_in_text = False
634+
635+
636+
class TrainModel(VerbatimStep):
637+
"""
638+
Now train a simple random forest. Before you do so, preprocess your data using StandardScaler.
639+
To directly apply your knowledge, replace the “?” with the correct code.
640+
641+
__copyable__
642+
import pandas as pd
643+
from sklearn.model_selection import train_test_split
644+
from sklearn.preprocessing import StandardScaler
645+
from sklearn.ensemble import RandomForestClassifier
646+
from sklearn.metrics import accuracy_score
647+
from sklearn.model_selection import cross_val_score
648+
from sklearn.model_selection import GridSearchCV
649+
import pyodide_http
650+
651+
pyodide_http.patch_all() # Necessary for downloading
652+
653+
# Load data using pandas
654+
data = pd.read_csv('https://raw.githubusercontent.com/aoberm/futurecoder/master/Datasets/Customer.csv')
655+
656+
# Separate features and target variable
657+
X = data.drop('Change', axis=1)
658+
y = data['Change']
659+
660+
# Splitting the data into training and testing sets
661+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
662+
663+
# Standardizing the features (optional for Random Forest, but we'll keep it for consistency)
664+
scaler = StandardScaler()
665+
X_train = scaler.fit_transform(?)
666+
X_test = scaler.transform(?)
667+
668+
# Training a Random Forest model
669+
model = RandomForestClassifier(random_state=42)
670+
model.fit(?, ?)
671+
"""
672+
673+
requirements = "hints"
674+
hints = """ test """
675+
676+
def program(self):
677+
import numpy as np
678+
import pandas as pd
679+
from sklearn.model_selection import train_test_split
680+
from sklearn.preprocessing import StandardScaler
681+
from sklearn.ensemble import RandomForestClassifier
682+
from sklearn.metrics import accuracy_score
683+
from sklearn.model_selection import cross_val_score
684+
from sklearn.model_selection import GridSearchCV
685+
import pyodide_http
686+
687+
pyodide_http.patch_all() # Necessary for downloading
688+
689+
# Load data using pandas
690+
data = pd.read_csv('https://raw.githubusercontent.com/aoberm/futurecoder/master/Datasets/Customer.csv')
691+
692+
# Separate features and target variable
693+
X = data.drop('Change', axis=1)
694+
y = data['Change']
695+
696+
# Splitting the data into training and testing sets
697+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
698+
699+
# Standardizing the features (optional for Random Forest, but we'll keep it for consistency)
700+
scaler = StandardScaler()
701+
X_train = scaler.fit_transform(X_train)
702+
X_test = scaler.transform(X_test)
703+
704+
# Training a Random Forest model
705+
model = RandomForestClassifier(random_state=42)
706+
model.fit(X_train, y_train)
707+
708+
709+
program_in_text = False
710+
711+
class TrainModel(VerbatimStep):
712+
"""
713+
Now you can make predictions on the test set and evaluate the performance of your model using metrics like accuracy.
714+
To directly apply your knowledge, replace the “?” with the correct code.
715+
716+
__copyable__
717+
import numpy as np
718+
import pandas as pd
719+
from sklearn.model_selection import train_test_split
720+
from sklearn.preprocessing import StandardScaler
721+
from sklearn.ensemble import RandomForestClassifier
722+
from sklearn.metrics import accuracy_score
723+
from sklearn.model_selection import cross_val_score
724+
from sklearn.model_selection import GridSearchCV
725+
import pyodide_http
726+
727+
pyodide_http.patch_all() # Necessary for downloading
728+
729+
# Load data using pandas
730+
data = pd.read_csv('https://raw.githubusercontent.com/aoberm/futurecoder/master/Datasets/Customer.csv')
731+
732+
# Separate features and target variable
733+
X = data.drop('Change', axis=1)
734+
y = data['Change']
735+
736+
# Splitting the data into training and testing sets
737+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
738+
739+
# Standardizing the features (optional for Random Forest, but we'll keep it for consistency)
740+
scaler = StandardScaler()
741+
X_train = scaler.fit_transform(X_train)
742+
X_test = scaler.transform(X_test)
743+
744+
# Training a Random Forest model
745+
model = RandomForestClassifier(random_state=42)
746+
model.fit(X_train, y_train)
747+
748+
# Making predictions
749+
y_pred = model.predict(?)
750+
751+
# Evaluating the model
752+
accuracy = accuracy_score(?, ?)
753+
print(f'Accuracy: {accuracy * 100:.2f}%')
754+
755+
"""
756+
757+
requirements = "hints"
758+
hints = """ test """
759+
760+
def program(self):
761+
import numpy as np
762+
import pandas as pd
763+
from sklearn.model_selection import train_test_split
764+
from sklearn.preprocessing import StandardScaler
765+
from sklearn.ensemble import RandomForestClassifier
766+
from sklearn.metrics import accuracy_score
767+
from sklearn.model_selection import cross_val_score
768+
from sklearn.model_selection import GridSearchCV
769+
import pyodide_http
770+
771+
pyodide_http.patch_all() # Necessary for downloading
772+
773+
# Load data using pandas
774+
data = pd.read_csv('https://raw.githubusercontent.com/aoberm/futurecoder/master/Datasets/Customer.csv')
775+
776+
# Separate features and target variable
777+
X = data.drop('Change', axis=1)
778+
y = data['Change']
779+
780+
# Splitting the data into training and testing sets
781+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
782+
783+
# Standardizing the features (optional for Random Forest, but we'll keep it for consistency)
784+
scaler = StandardScaler()
785+
X_train = scaler.fit_transform(X_train)
786+
X_test = scaler.transform(X_test)
787+
788+
# Training a Random Forest model
789+
model = RandomForestClassifier(random_state=42)
790+
model.fit(X_train, y_train)
791+
792+
# Making predictions
793+
y_pred = model.predict(X_test)
794+
795+
# Evaluating the model
796+
accuracy = accuracy_score(y_test, y_pred)
797+
print(f'Accuracy: {accuracy * 100:.2f}%')
798+
799+
program_in_text = False
800+
801+
final_text = """
802+
Good job! You have managed to train your own model. Now you can apply your knowledge to various data analysis tasks!
803+
"""
521804

522805

523806

0 commit comments

Comments
 (0)