This commit is contained in:
Тукаева Альфия 2025-01-08 18:22:03 +04:00
parent 595a505c62
commit 8c645b301b
9 changed files with 2158 additions and 106 deletions

3
.idea/.gitignore vendored
View File

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="NUMPY" />
<option name="myDocStringFormat" value="NumPy" />
</component>
</module>

View File

@ -1,13 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyInterpreterInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="str.__pos__" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View File

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ckmai.iml" filepath="$PROJECT_DIR$/.idea/ckmai.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

8
.idea/workspace.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;last_opened_file_path&quot;: &quot;C:/Users/Альфия/PycharmProjects&quot;
}
}</component>
</project>

2149
lab4.ipynb Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,12 +1,9 @@
import math import math
from typing import Dict, Tuple from typing import Dict, Tuple
import numpy as np
import pandas as pd import pandas as pd
from pandas import DataFrame from pandas import DataFrame
from sklearn import metrics
from sklearn.model_selection import train_test_split from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
def split_stratified_into_train_val_test( def split_stratified_into_train_val_test(
@ -82,57 +79,3 @@ def split_stratified_into_train_val_test(
assert len(df_input) == len(df_train) + len(df_val) + len(df_test) assert len(df_input) == len(df_train) + len(df_val) + len(df_test)
return df_train, df_val, df_test, y_train, y_val, y_test return df_train, df_val, df_test, y_train, y_val, y_test
def run_classification(
model: Pipeline,
X_train: DataFrame,
X_test: DataFrame,
y_train: DataFrame,
y_test: DataFrame,
) -> Dict:
result = {}
y_train_predict = model.predict(X_train)
y_test_probs = model.predict_proba(X_test)[:, 1]
y_test_predict = np.where(y_test_probs > 0.5, 1, 0)
result["pipeline"] = model
result["probs"] = y_test_probs
result["preds"] = y_test_predict
result["Precision_train"] = metrics.precision_score(y_train, y_train_predict)
result["Precision_test"] = metrics.precision_score(y_test, y_test_predict)
result["Recall_train"] = metrics.recall_score(y_train, y_train_predict)
result["Recall_test"] = metrics.recall_score(y_test, y_test_predict)
result["Accuracy_train"] = metrics.accuracy_score(y_train, y_train_predict)
result["Accuracy_test"] = metrics.accuracy_score(y_test, y_test_predict)
result["ROC_AUC_test"] = metrics.roc_auc_score(y_test, y_test_probs)
result["F1_train"] = metrics.f1_score(y_train, y_train_predict)
result["F1_test"] = metrics.f1_score(y_test, y_test_predict)
result["MCC_test"] = metrics.matthews_corrcoef(y_test, y_test_predict)
result["Cohen_kappa_test"] = metrics.cohen_kappa_score(y_test, y_test_predict)
result["Confusion_matrix"] = metrics.confusion_matrix(y_test, y_test_predict)
return result
def run_regression(
model: Pipeline,
X_train: DataFrame,
X_test: DataFrame,
y_train: DataFrame,
y_test: DataFrame,
) -> Dict:
result = {}
y_train_pred = model.predict(X_train.values)
y_test_pred = model.predict(X_test.values)
result["fitted"] = model
result["train_preds"] = y_train_pred
result["preds"] = y_test_pred
result["RMSE_train"] = math.sqrt(metrics.mean_squared_error(y_train, y_train_pred))
result["RMSE_test"] = math.sqrt(metrics.mean_squared_error(y_test, y_test_pred))
result["RMAE_test"] = math.sqrt(metrics.mean_absolute_error(y_test, y_test_pred))
result["R2_test"] = metrics.r2_score(y_test, y_test_pred)
return result