import%20marimo%0A%0A__generated_with%20%3D%20%220.16.0%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20import%20pandas%20as%20pd%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20seaborn%20as%20sns%0A%20%20%20%20return%20mo%2C%20pd%2C%20sns%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%20Module%203%3A%20%5BClassification%5D(https%3A%2F%2Fgithub.com%2FDataTalksClub%2Fmachine-learning-zoomcamp%2Ftree%2Fmaster%2F03-classification)%0A%0A%20%20%20%20%23%23%20Homework%0A%0A%20%20%20%20%23%23%23%20Dataset%0A%0A%20%20%20%20For%20this%20homework%2C%20we'll%20use%20the%20Bank%20Marketing%20dataset.%20Download%20it%20from%20here.%20You%20can%20do%20it%20with%20wget%3A%0A%0A%20%20%20%20wget%20https%3A%2F%2Fraw.githubusercontent.com%2Falexeygrigorev%2Fdatasets%2Fmaster%2Fcourse_lead_scoring.csv%0A%0A%20%20%20%20In%20this%20dataset%20our%20desired%20target%20for%20classification%20task%20will%20be%20**converted**%20variable%20-%20has%20the%20client%20signed%20up%20to%20the%20platform%20or%20not.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(pd)%3A%0A%20%20%20%20def%20read_dataframe()%3A%0A%20%20%20%20%20%20%20%20return%20pd.read_csv(%22.%2Fmodule-3%2Fdata%2Fcourse_lead_scoring.csv%22)%0A%0A%20%20%20%20raw_dataframe%20%3D%20read_dataframe()%0A%20%20%20%20raw_dataframe.head()%0A%20%20%20%20return%20(raw_dataframe%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20List%20Numeric%20and%20Categorical%20Columns%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(raw_dataframe)%3A%0A%20%20%20%20raw_dataframe.dtypes%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20numeric_columns%20%3D%20%5B%22number_of_courses_viewed%22%2C%20%22annual_income%22%2C%20%22interaction_count%22%2C%20%22lead_score%22%5D%0A%20%20%20%20categorical_columns%20%3D%20%5B%22lead_source%22%2C%20%22industry%22%2C%20%22employment_status%22%2C%20%22location%22%5D%0A%20%20%20%20return%20categorical_columns%2C%20numeric_columns%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Data%20Preparation%0A%0A%20%20%20%20%23%23%23%20Check%20if%20the%20missing%20values%20are%20presented%20in%20the%20features%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(raw_dataframe)%3A%0A%20%20%20%20raw_dataframe.isnull().sum()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20For%20categorical%20features%2C%20replace%20them%20with%20'NA'%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(categorical_columns%2C%20raw_dataframe)%3A%0A%20%20%20%20def%20fill_categorical_values(dataframe)%3A%0A%20%20%20%20%20%20%20%20dataframe%5Bcategorical_columns%5D%20%3D%20dataframe%5Bcategorical_columns%5D.fillna('NA')%0A%0A%20%20%20%20%20%20%20%20return%20dataframe%0A%0A%20%20%20%20fill_categorical_values(raw_dataframe).head()%0A%20%20%20%20return%20(fill_categorical_values%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%23%23%23%20For%20numerical%20features%2C%20replace%20with%20with%200.0%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(numeric_columns%2C%20raw_dataframe)%3A%0A%20%20%20%20def%20fill_numerical_values(dataframe)%3A%0A%20%20%20%20%20%20%20%20dataframe%5Bnumeric_columns%5D%20%3D%20dataframe%5Bnumeric_columns%5D.fillna(0)%0A%0A%20%20%20%20%20%20%20%20return%20dataframe%0A%0A%20%20%20%20fill_numerical_values(raw_dataframe).head()%0A%20%20%20%20return%20(fill_numerical_values%2C)%0A%0A%0A%40app.cell%0Adef%20_(fill_categorical_values%2C%20fill_numerical_values%2C%20raw_dataframe)%3A%0A%20%20%20%20filled_dataframe%20%3D%20fill_categorical_values(raw_dataframe)%0A%20%20%20%20filled_dataframe%20%3D%20fill_numerical_values(filled_dataframe)%0A%20%20%20%20filled_dataframe.head()%0A%20%20%20%20return%20(filled_dataframe%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Question%201%0A%0A%20%20%20%20What%20is%20the%20most%20frequent%20observation%20(mode)%20for%20the%20column%20%60industry%60%3F%0A%0A%20%20%20%20-%20%60NA%60%0A%20%20%20%20-%20%60technology%60%0A%20%20%20%20-%20%60healthcare%60%0A%20%20%20%20-%20%60retail%60%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(filled_dataframe)%3A%0A%20%20%20%20filled_dataframe.industry.mode()%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Question%202%0A%0A%20%20%20%20Create%20the%20%5Bcorrelation%20matrix%5D(https%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3Dcorrelation%2Bmatrix)%20for%20the%20numerical%20features%20of%20your%20dataset.%20%0A%20%20%20%20In%20a%20correlation%20matrix%2C%20you%20compute%20the%20correlation%20coefficient%20between%20every%20pair%20of%20features.%0A%0A%20%20%20%20What%20are%20the%20two%20features%20that%20have%20the%20biggest%20correlation%3F%0A%0A%20%20%20%20-%20%60interaction_count%60%20and%20%60lead_score%60%0A%20%20%20%20-%20%60number_of_courses_viewed%60%20and%20%60lead_score%60%0A%20%20%20%20-%20%60number_of_courses_viewed%60%20and%20%60interaction_count%60%0A%20%20%20%20-%20%60annual_income%60%20and%20%60interaction_count%60%0A%0A%20%20%20%20Only%20consider%20the%20pairs%20above%20when%20answering%20this%20question.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(filled_dataframe%2C%20numeric_columns)%3A%0A%20%20%20%20filled_dataframe%5Bnumeric_columns%5D.corr()%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(filled_dataframe%2C%20numeric_columns%2C%20sns)%3A%0A%20%20%20%20sns.heatmap(filled_dataframe%5Bnumeric_columns%5D.corr()%2C%20annot%3DTrue)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20pair%20of%20features%20with%20greatest%20correlation%20is%20%60annual_income%60%20and%20%60interaction_count%60.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%23%20Split%20the%20data%0A%0A%20%20%20%20*%20Split%20your%20data%20in%20train%2Fval%2Ftest%20sets%20with%2060%25%2F20%25%2F20%25%20distribution.%0A%20%20%20%20*%20Use%20Scikit-Learn%20for%20that%20(the%20%60train_test_split%60%20function)%20and%20set%20the%20seed%20to%20%6042%60.%0A%20%20%20%20*%20Make%20sure%20that%20the%20target%20value%20%60y%60%20is%20not%20in%20your%20dataframe.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(filled_dataframe%2C%20raw_dataframe)%3A%0A%20%20%20%20from%20sklearn.model_selection%20import%20train_test_split%0A%0A%20%20%20%20full_dataframe%2C%20test_dataframe%20%3D%20train_test_split(filled_dataframe%2C%20test_size%3D0.2)%0A%20%20%20%20train_dataframe%2C%20val_dataframe%20%3D%20train_test_split(full_dataframe%2C%20test_size%3D0.25)%0A%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22raw_size%22%3A%20len(raw_dataframe)%2C%0A%20%20%20%20%20%20%20%20%22full_size%22%3A%20len(full_dataframe)%2C%0A%20%20%20%20%20%20%20%20%22train_size%22%3A%20len(train_dataframe)%2C%0A%20%20%20%20%20%20%20%20%22val_size%22%3A%20len(val_dataframe)%2C%0A%20%20%20%20%20%20%20%20%22test_size%22%3A%20len(test_dataframe)%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%20train_dataframe%2C%20val_dataframe%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Question%203%0A%0A%20%20%20%20*%20Calculate%20the%20mutual%20information%20score%20between%20%60y%60%20and%20other%20categorical%20variables%20in%20the%20dataset.%20Use%20the%20training%20set%20only.%0A%20%20%20%20*%20Round%20the%20scores%20to%202%20decimals%20using%20%60round(score%2C%202)%60.%0A%0A%20%20%20%20Which%20of%20these%20variables%20has%20the%20biggest%20mutual%20information%20score%3F%0A%0A%20%20%20%20-%20%60industry%60%0A%20%20%20%20-%20%60location%60%0A%20%20%20%20-%20%60lead_source%60%0A%20%20%20%20-%20%60employment_status%60%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(train_dataframe)%3A%0A%20%20%20%20from%20sklearn.metrics%20import%20mutual_info_score%0A%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22industry%22%3A%20round(mutual_info_score(train_dataframe.industry%2C%20train_dataframe.converted)%2C%202)%2C%0A%20%20%20%20%20%20%20%20%22location%22%3A%20round(mutual_info_score(train_dataframe.location%2C%20train_dataframe.converted)%2C%202)%2C%0A%20%20%20%20%20%20%20%20%22lead_source%22%3A%20round(mutual_info_score(train_dataframe.lead_source%2C%20train_dataframe.converted)%2C%202)%2C%0A%20%20%20%20%20%20%20%20%22employment_status%22%3A%20round(mutual_info_score(train_dataframe.employment_status%2C%20train_dataframe.converted)%2C%202)%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20variable%20with%20biggest%20mutual%20information%20score%20(compared%20with%20our%20**y**%20variable)%20is%20**lead_source**.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Question%204%0A%0A%20%20%20%20*%20Now%20let's%20train%20a%20logistic%20regression.%0A%20%20%20%20*%20Remember%20that%20we%20have%20several%20categorical%20variables%20in%20the%20dataset.%20Include%20them%20using%20one-hot%20encoding.%0A%20%20%20%20*%20Fit%20the%20model%20on%20the%20training%20dataset.%0A%20%20%20%20%20%20%20%20-%20To%20make%20sure%20the%20results%20are%20reproducible%20across%20different%20versions%20of%20Scikit-Learn%2C%20fit%20the%20model%20with%20these%20parameters%3A%0A%20%20%20%20%20%20%20%20-%20%60model%20%3D%20LogisticRegression(solver%3D'liblinear'%2C%20C%3D1.0%2C%20max_iter%3D1000%2C%20random_state%3D42)%60%0A%20%20%20%20*%20Calculate%20the%20accuracy%20on%20the%20validation%20dataset%20and%20round%20it%20to%202%20decimal%20digits.%0A%0A%20%20%20%20What%20accuracy%20did%20you%20get%3F%0A%0A%20%20%20%20-%200.64%0A%20%20%20%20-%200.74%0A%20%20%20%20-%200.84%0A%20%20%20%20-%200.94%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(categorical_columns%2C%20numeric_columns%2C%20train_dataframe)%3A%0A%20%20%20%20from%20sklearn.feature_extraction%20import%20DictVectorizer%0A%0A%20%20%20%20def%20get_dict_vectorizer(dataframe)%3A%0A%20%20%20%20%20%20%20%20dict_vectorizer%20%3D%20DictVectorizer(sparse%3DFalse)%0A%20%20%20%20%20%20%20%20dictionary%20%3D%20dataframe%5Bnumeric_columns%20%2B%20categorical_columns%5D.to_dict(orient%3D%22records%22)%0A%20%20%20%20%20%20%20%20dict_vectorizer.fit(dictionary)%0A%0A%20%20%20%20%20%20%20%20return%20dict_vectorizer%0A%0A%20%20%20%20train_dict_vectorizer%20%3D%20get_dict_vectorizer(train_dataframe)%0A%20%20%20%20return%20DictVectorizer%2C%20train_dict_vectorizer%0A%0A%0A%40app.cell%0Adef%20_(categorical_columns%2C%20numeric_columns)%3A%0A%20%20%20%20def%20prepare_dataframe(dataframe%2C%20dict_vectorizer)%3A%0A%20%20%20%20%20%20%20%20y%20%3D%20dataframe.converted%0A%0A%20%20%20%20%20%20%20%20copy%20%3D%20dataframe.copy()%0A%20%20%20%20%20%20%20%20del%20copy%5B%22converted%22%5D%0A%0A%20%20%20%20%20%20%20%20dictionary%20%3D%20dataframe%5Bnumeric_columns%20%2B%20categorical_columns%5D.to_dict(orient%3D%22records%22)%0A%20%20%20%20%20%20%20%20X%20%3D%20dict_vectorizer.transform(dictionary)%0A%0A%20%20%20%20%20%20%20%20return%20X%2C%20y%0A%20%20%20%20return%20(prepare_dataframe%2C)%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20prepare_dataframe%2C%0A%20%20%20%20train_dataframe%2C%0A%20%20%20%20train_dict_vectorizer%2C%0A%20%20%20%20val_dataframe%2C%0A)%3A%0A%20%20%20%20from%20sklearn.linear_model%20import%20LogisticRegression%0A%0A%20%20%20%20def%20eval_model()%3A%0A%20%20%20%20%20%20%20%20X_train%2C%20y_train%20%3D%20prepare_dataframe(train_dataframe%2C%20train_dict_vectorizer)%0A%0A%20%20%20%20%20%20%20%20model%20%3D%20LogisticRegression(solver%3D'liblinear'%2C%20C%3D1.0%2C%20max_iter%3D1000%2C%20random_state%3D42)%0A%20%20%20%20%20%20%20%20model.fit(X_train%2C%20y_train)%0A%0A%20%20%20%20%20%20%20%20X_val%2C%20y_val%20%3D%20prepare_dataframe(val_dataframe%2C%20train_dict_vectorizer)%0A%0A%20%20%20%20%20%20%20%20return%20round(model.score(X_val%2C%20y_val)%2C%202)%0A%0A%20%20%20%20eval_model()%0A%20%20%20%20return%20(LogisticRegression%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Question%205%20%0A%0A%20%20%20%20*%20Let's%20find%20the%20least%20useful%20feature%20using%20the%20*feature%20elimination*%20technique.%0A%20%20%20%20*%20Train%20a%20model%20using%20the%20same%20features%20and%20parameters%20as%20in%20Q4%20(without%20rounding).%0A%20%20%20%20*%20Now%20exclude%20each%20feature%20from%20this%20set%20and%20train%20a%20model%20without%20it.%20Record%20the%20accuracy%20for%20each%20model.%0A%20%20%20%20*%20For%20each%20feature%2C%20calculate%20the%20difference%20between%20the%20original%20accuracy%20and%20the%20accuracy%20without%20the%20feature.%20%0A%0A%20%20%20%20Which%20of%20following%20feature%20has%20the%20smallest%20difference%3F%0A%0A%20%20%20%20-%20%60'industry'%60%0A%20%20%20%20-%20%60'employment_status'%60%0A%20%20%20%20-%20%60'lead_score'%60%0A%0A%20%20%20%20%3E%20**Note**%3A%20The%20difference%20doesn't%20have%20to%20be%20positive.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20DictVectorizer%2C%0A%20%20%20%20LogisticRegression%2C%0A%20%20%20%20categorical_columns%2C%0A%20%20%20%20numeric_columns%2C%0A%20%20%20%20train_dataframe%2C%0A%20%20%20%20val_dataframe%2C%0A)%3A%0A%20%20%20%20def%20get_reduced_dict_vectorizer(dataframe%2C%20ignored_column)%3A%0A%20%20%20%20%20%20%20%20dict_vectorizer%20%3D%20DictVectorizer(sparse%3DFalse)%0A%0A%20%20%20%20%20%20%20%20reduced_columns%20%3D%20numeric_columns%20%2B%20categorical_columns%0A%20%20%20%20%20%20%20%20reduced_columns.remove(ignored_column)%0A%0A%20%20%20%20%20%20%20%20dictionary%20%3D%20dataframe%5Breduced_columns%5D.to_dict(orient%3D%22records%22)%0A%20%20%20%20%20%20%20%20dict_vectorizer.fit(dictionary)%0A%0A%20%20%20%20%20%20%20%20return%20dict_vectorizer%0A%0A%20%20%20%20def%20prepare_reduced_dataframe(dataframe%2C%20dict_vectorizer%2C%20ignored_column)%3A%0A%20%20%20%20%20%20%20%20y%20%3D%20dataframe.converted%0A%0A%20%20%20%20%20%20%20%20copy%20%3D%20dataframe.copy()%0A%20%20%20%20%20%20%20%20del%20copy%5B%22converted%22%5D%0A%0A%20%20%20%20%20%20%20%20reduced_columns%20%3D%20numeric_columns%20%2B%20categorical_columns%0A%20%20%20%20%20%20%20%20reduced_columns.remove(ignored_column)%0A%0A%20%20%20%20%20%20%20%20dictionary%20%3D%20dataframe%5Breduced_columns%5D.to_dict(orient%3D%22records%22)%0A%20%20%20%20%20%20%20%20X%20%3D%20dict_vectorizer.transform(dictionary)%0A%0A%20%20%20%20%20%20%20%20return%20X%2C%20y%0A%0A%20%20%20%20def%20evaluate_without_feature(train_dataframe%2C%20val_dataframe%2C%20ignored_column)%3A%0A%20%20%20%20%20%20%20%20train_reduced_dataframe%20%3D%20train_dataframe.copy()%0A%20%20%20%20%20%20%20%20del%20train_reduced_dataframe%5Bignored_column%5D%0A%0A%20%20%20%20%20%20%20%20train_reduced_dict_vectorizer%20%3D%20get_reduced_dict_vectorizer(train_reduced_dataframe%2C%20ignored_column)%0A%0A%20%20%20%20%20%20%20%20X_train_reduced%2C%20y_train_reduced%20%3D%20prepare_reduced_dataframe(%0A%20%20%20%20%20%20%20%20%20%20%20%20train_reduced_dataframe%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20train_reduced_dict_vectorizer%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20ignored_column%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20model_reduced%20%3D%20LogisticRegression(solver%3D'liblinear'%2C%20C%3D1.0%2C%20max_iter%3D1000%2C%20random_state%3D42)%0A%20%20%20%20%20%20%20%20model_reduced.fit(X_train_reduced%2C%20y_train_reduced)%0A%0A%20%20%20%20%20%20%20%20val_reduced_dataframe%20%3D%20val_dataframe.copy()%0A%20%20%20%20%20%20%20%20del%20val_reduced_dataframe%5Bignored_column%5D%0A%0A%20%20%20%20%20%20%20%20X_val_reduced%2C%20y_val_reduced%20%3D%20prepare_reduced_dataframe(%0A%20%20%20%20%20%20%20%20%20%20%20%20val_reduced_dataframe%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20train_reduced_dict_vectorizer%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20ignored_column%0A%20%20%20%20%20%20%20%20)%0A%0A%20%20%20%20%20%20%20%20return%20round(model_reduced.score(X_val_reduced%2C%20y_val_reduced)%2C%202)%0A%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%22industry%22%3A%20evaluate_without_feature(train_dataframe%2C%20val_dataframe%2C%20%22industry%22)%2C%0A%20%20%20%20%20%20%20%20%22employment_status%22%3A%20evaluate_without_feature(train_dataframe%2C%20val_dataframe%2C%20%22employment_status%22)%2C%0A%20%20%20%20%20%20%20%20%22lead_score%22%3A%20evaluate_without_feature(train_dataframe%2C%20val_dataframe%2C%20%22lead_score%22)%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20feature%20that%20caused%20the%20smallest%20change%20was%20**lead_score**.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Question%206%0A%0A%20%20%20%20*%20Now%20let's%20train%20a%20regularized%20logistic%20regression.%0A%20%20%20%20*%20Let's%20try%20the%20following%20values%20of%20the%20parameter%20%60C%60%3A%20%60%5B0.01%2C%200.1%2C%201%2C%2010%2C%20100%5D%60.%0A%20%20%20%20*%20Train%20models%20using%20all%20the%20features%20as%20in%20Q4.%0A%20%20%20%20*%20Calculate%20the%20accuracy%20on%20the%20validation%20dataset%20and%20round%20it%20to%203%20decimal%20digits.%0A%0A%20%20%20%20Which%20of%20these%20%60C%60%20leads%20to%20the%20best%20accuracy%20on%20the%20validation%20set%3F%0A%0A%20%20%20%20-%200.01%0A%20%20%20%20-%200.1%0A%20%20%20%20-%201%0A%20%20%20%20-%2010%0A%20%20%20%20-%20100%0A%0A%20%20%20%20%3E%20**Note**%3A%20If%20there%20are%20multiple%20options%2C%20select%20the%20smallest%20%60C%60.%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20LogisticRegression%2C%0A%20%20%20%20prepare_dataframe%2C%0A%20%20%20%20train_dataframe%2C%0A%20%20%20%20train_dict_vectorizer%2C%0A%20%20%20%20val_dataframe%2C%0A)%3A%0A%20%20%20%20def%20eval_model_parameter(C)%3A%0A%20%20%20%20%20%20%20%20X_train%2C%20y_train%20%3D%20prepare_dataframe(train_dataframe%2C%20train_dict_vectorizer)%0A%0A%20%20%20%20%20%20%20%20model%20%3D%20LogisticRegression(solver%3D'liblinear'%2C%20C%3DC%2C%20max_iter%3D1000%2C%20random_state%3D42)%0A%20%20%20%20%20%20%20%20model.fit(X_train%2C%20y_train)%0A%0A%20%20%20%20%20%20%20%20X_val%2C%20y_val%20%3D%20prepare_dataframe(val_dataframe%2C%20train_dict_vectorizer)%0A%0A%20%20%20%20%20%20%20%20return%20round(model.score(X_val%2C%20y_val)%2C%202)%0A%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%220.01%22%3A%20eval_model_parameter(0.01)%2C%0A%20%20%20%20%20%20%20%20%220.1%22%3A%20eval_model_parameter(0.1)%2C%0A%20%20%20%20%20%20%20%20%221%22%3A%20eval_model_parameter(1)%2C%0A%20%20%20%20%20%20%20%20%2210%22%3A%20eval_model_parameter(10)%2C%0A%20%20%20%20%20%20%20%20%22100%22%3A%20eval_model_parameter(100)%2C%0A%20%20%20%20%7D%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22The%20value%20C%20%3D%20**0.01**%20lead%20for%20the%20greatest%20accuracy.%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%0A%20%20%20%20%20%20%20%20r%22%22%22%0A%20%20%20%20%23%23%20Submit%20the%20results%0A%0A%20%20%20%20*%20Submit%20your%20results%20here%3A%20https%3A%2F%2Fcourses.datatalks.club%2Fml-zoomcamp-2025%2Fhomework%2Fhw03%0A%20%20%20%20*%20If%20your%20answer%20doesn't%20match%20options%20exactly%2C%20select%20the%20closest%20one%0A%20%20%20%20%22%22%22%0A%20%20%20%20)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
7a44e84ed1504e3d31d2c1bc8b386793483f99a4ea243519a6ef86fd8934f742