diff --git a/2023/homework/WangTianlong/homework_credit_scoring.ipynb b/2023/homework/WangTianlong/homework_credit_scoring.ipynb
new file mode 100644
index 00000000..c2f7845d
--- /dev/null
+++ b/2023/homework/WangTianlong/homework_credit_scoring.ipynb
@@ -0,0 +1,1219 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# 一起来打怪之 Credit Scoring 练习"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "---\n",
+ "## 作业说明\n",
+ "\n",
+ "- 答题步骤:\n",
+ " - 回答问题**请保留每一步**操作过程,请不要仅仅给出最后答案\n",
+ " - 请养成代码注释的好习惯\n",
+ "\n",
+ "- 解题思路:\n",
+ " - 为方便大家准确理解题目,在习题实战中有所收获,本文档提供了解题思路提示\n",
+ " - 解题思路**仅供参考**,鼓励原创解题方法\n",
+ " - 为督促同学们自己思考,解题思路内容设置为**白色**,必要时请从冒号后拖动鼠标查看\n",
+ "\n",
+ "- 所用数据\n",
+ " - 请注意导入数据库后先**查看和了解数据的基本性质**,后面的问题不再一一提醒"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## machine learning for credit scoring\n",
+ "\n",
+ "\n",
+ "Banks play a crucial role in market economies. They decide who can get finance and on what terms and can make or break investment decisions. For markets and society to function, individuals and companies need access to credit. \n",
+ "\n",
+ "Credit scoring algorithms, which make a guess at the probability of default, are the method banks use to determine whether or not a loan should be granted. This competition requires participants to improve on the state of the art in credit scoring, by predicting the probability that somebody will experience financial distress in the next two years. [Dataset](https://www.kaggle.com/c/GiveMeSomeCredit)\n",
+ "\n",
+ "Attribute Information:\n",
+ "\n",
+ "|Variable Name\t|\tDescription\t|\tType|\n",
+ "|----|----|----|\n",
+ "|SeriousDlqin2yrs\t|\tPerson experienced 90 days past due delinquency or worse \t|\tY/N|\n",
+ "|RevolvingUtilizationOfUnsecuredLines\t|\tTotal balance on credit divided by the sum of credit limits\t|\tpercentage|\n",
+ "|age\t|\tAge of borrower in years\t|\tinteger|\n",
+ "|NumberOfTime30-59DaysPastDueNotWorse\t|\tNumber of times borrower has been 30-59 days past due |\tinteger|\n",
+ "|DebtRatio\t|\tMonthly debt payments\t|\tpercentage|\n",
+ "|MonthlyIncome\t|\tMonthly income\t|\treal|\n",
+ "|NumberOfOpenCreditLinesAndLoans\t|\tNumber of Open loans |\tinteger|\n",
+ "|NumberOfTimes90DaysLate\t|\tNumber of times borrower has been 90 days or more past due.\t|\tinteger|\n",
+ "|NumberRealEstateLoansOrLines\t|\tNumber of mortgage and real estate loans\t|\tinteger|\n",
+ "|NumberOfTime60-89DaysPastDueNotWorse\t|\tNumber of times borrower has been 60-89 days past due |integer|\n",
+ "|NumberOfDependents\t|\tNumber of dependents in family\t|\tinteger|\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "----------\n",
+ "## Read the data into Pandas "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 4,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "
\n",
+ "\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
\n",
+ "
SeriousDlqin2yrs
\n",
+ "
RevolvingUtilizationOfUnsecuredLines
\n",
+ "
age
\n",
+ "
NumberOfTime30-59DaysPastDueNotWorse
\n",
+ "
DebtRatio
\n",
+ "
MonthlyIncome
\n",
+ "
NumberOfOpenCreditLinesAndLoans
\n",
+ "
NumberOfTimes90DaysLate
\n",
+ "
NumberRealEstateLoansOrLines
\n",
+ "
NumberOfTime60-89DaysPastDueNotWorse
\n",
+ "
NumberOfDependents
\n",
+ "
\n",
+ " \n",
+ " \n",
+ "
\n",
+ "
0
\n",
+ "
1
\n",
+ "
0.766127
\n",
+ "
45.0
\n",
+ "
2.0
\n",
+ "
0.802982
\n",
+ "
9120.0
\n",
+ "
13.0
\n",
+ "
0.0
\n",
+ "
6.0
\n",
+ "
0.0
\n",
+ "
2.0
\n",
+ "
\n",
+ "
\n",
+ "
1
\n",
+ "
0
\n",
+ "
0.957151
\n",
+ "
40.0
\n",
+ "
0.0
\n",
+ "
0.121876
\n",
+ "
2600.0
\n",
+ "
4.0
\n",
+ "
0.0
\n",
+ "
0.0
\n",
+ "
0.0
\n",
+ "
1.0
\n",
+ "
\n",
+ "
\n",
+ "
2
\n",
+ "
0
\n",
+ "
0.658180
\n",
+ "
38.0
\n",
+ "
1.0
\n",
+ "
0.085113
\n",
+ "
3042.0
\n",
+ "
2.0
\n",
+ "
1.0
\n",
+ "
0.0
\n",
+ "
0.0
\n",
+ "
0.0
\n",
+ "
\n",
+ "
\n",
+ "
3
\n",
+ "
0
\n",
+ "
0.233810
\n",
+ "
30.0
\n",
+ "
0.0
\n",
+ "
0.036050
\n",
+ "
3300.0
\n",
+ "
5.0
\n",
+ "
0.0
\n",
+ "
0.0
\n",
+ "
0.0
\n",
+ "
0.0
\n",
+ "
\n",
+ "
\n",
+ "
4
\n",
+ "
0
\n",
+ "
0.907239
\n",
+ "
49.0
\n",
+ "
1.0
\n",
+ "
0.024926
\n",
+ "
63588.0
\n",
+ "
7.0
\n",
+ "
0.0
\n",
+ "
1.0
\n",
+ "
0.0
\n",
+ "
0.0
\n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
+ "text/plain": [
+ " SeriousDlqin2yrs RevolvingUtilizationOfUnsecuredLines age \\\n",
+ "0 1 0.766127 45.0 \n",
+ "1 0 0.957151 40.0 \n",
+ "2 0 0.658180 38.0 \n",
+ "3 0 0.233810 30.0 \n",
+ "4 0 0.907239 49.0 \n",
+ "\n",
+ " NumberOfTime30-59DaysPastDueNotWorse DebtRatio MonthlyIncome \\\n",
+ "0 2.0 0.802982 9120.0 \n",
+ "1 0.0 0.121876 2600.0 \n",
+ "2 1.0 0.085113 3042.0 \n",
+ "3 0.0 0.036050 3300.0 \n",
+ "4 1.0 0.024926 63588.0 \n",
+ "\n",
+ " NumberOfOpenCreditLinesAndLoans NumberOfTimes90DaysLate \\\n",
+ "0 13.0 0.0 \n",
+ "1 4.0 0.0 \n",
+ "2 2.0 1.0 \n",
+ "3 5.0 0.0 \n",
+ "4 7.0 0.0 \n",
+ "\n",
+ " NumberRealEstateLoansOrLines NumberOfTime60-89DaysPastDueNotWorse \\\n",
+ "0 6.0 0.0 \n",
+ "1 0.0 0.0 \n",
+ "2 0.0 0.0 \n",
+ "3 0.0 0.0 \n",
+ "4 1.0 0.0 \n",
+ "\n",
+ " NumberOfDependents \n",
+ "0 2.0 \n",
+ "1 1.0 \n",
+ "2 0.0 \n",
+ "3 0.0 \n",
+ "4 0.0 "
+ ]
+ },
+ "execution_count": 4,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "import pandas as pd\n",
+ "pd.set_option('display.max_columns', 500)\n",
+ "import zipfile\n",
+ "with zipfile.ZipFile('KaggleCredit2.csv.zip', 'r') as z:\n",
+ " f = z.open('KaggleCredit2.csv')\n",
+ " data = pd.read_csv(f, index_col=0)\n",
+ "data.head()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(112915, 11)"
+ ]
+ },
+ "execution_count": 5,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "data.shape"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "------------\n",
+ "## Drop na"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "SeriousDlqin2yrs 0\n",
+ "RevolvingUtilizationOfUnsecuredLines 0\n",
+ "age 4267\n",
+ "NumberOfTime30-59DaysPastDueNotWorse 0\n",
+ "DebtRatio 0\n",
+ "MonthlyIncome 0\n",
+ "NumberOfOpenCreditLinesAndLoans 0\n",
+ "NumberOfTimes90DaysLate 0\n",
+ "NumberRealEstateLoansOrLines 0\n",
+ "NumberOfTime60-89DaysPastDueNotWorse 0\n",
+ "NumberOfDependents 4267\n",
+ "dtype: int64"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "data.isnull().sum(axis=0)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 7,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "(108648, 11)"
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "data.dropna(inplace=True)\n",
+ "data.shape"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "---------\n",
+ "## Create X and y"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 8,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [],
+ "source": [
+ "y = data['SeriousDlqin2yrs']\n",
+ "X = data.drop('SeriousDlqin2yrs', axis=1)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 9,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "0.06742876076872101"
+ ]
+ },
+ "execution_count": 9,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "y.mean()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "---\n",
+ "## 练习1:把数据切分成训练集和测试集\n",
+ "- 提示:from sklearn.model_selection import train_test_split('Gender') "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 10,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [],
+ "source": [
+ "from sklearn.model_selection import train_test_split\n",
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "----\n",
+ "## 练习2:使用logistic regression/决策树/SVM/KNN...等sklearn分类算法进行分类\n",
+ "尝试查sklearn API了解模型参数含义,调整不同的参数"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Logistic regression\n",
+ "- 提示:from sklearn import linear_model('Gender') "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ },
+ "scrolled": true
+ },
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Accuracy: 0.9319374137137598\n"
+ ]
+ },
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\linear_model\\_logistic.py:458: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
+ "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
+ "\n",
+ "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
+ " https://scikit-learn.org/stable/modules/preprocessing.html\n",
+ "Please also refer to the documentation for alternative solver options:\n",
+ " https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
+ " n_iter_i = _check_optimize_result(\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ }
+ ],
+ "source": [
+ "from sklearn.linear_model import LogisticRegression\n",
+ "from sklearn.metrics import accuracy_score\n",
+ "model = LogisticRegression()\n",
+ "model.fit(X_train, y_train)\n",
+ "y_pred = model.predict(X_test)\n",
+ "accuracy = accuracy_score(y_test, y_pred)\n",
+ "print(\"Accuracy:\", accuracy)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Decision Tree\n",
+ "- 提示:from sklearn.tree import DecisionTreeClassifier('Gender') "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Accuracy: 0.8938794293603314\n"
+ ]
+ },
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ }
+ ],
+ "source": [
+ "from sklearn.tree import DecisionTreeClassifier\n",
+ "model = DecisionTreeClassifier(random_state=42)\n",
+ "model.fit(X_train, y_train)\n",
+ "y_pred = model.predict(X_test)\n",
+ "accuracy = accuracy_score(y_test, y_pred)\n",
+ "print(\"Accuracy:\", accuracy)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Random Forest\n",
+ "- 提示:from sklearn.ensemble import RandomForestClassifier('Gender') "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 13,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Accuracy: 0.9340082834790612\n"
+ ]
+ },
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ }
+ ],
+ "source": [
+ "from sklearn.ensemble import RandomForestClassifier\n",
+ "model =RandomForestClassifier(random_state=42)\n",
+ "model.fit(X_train, y_train)\n",
+ "y_pred = model.predict(X_test)\n",
+ "accuracy = accuracy_score(y_test, y_pred)\n",
+ "print(\"Accuracy:\", accuracy)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### SVM\n",
+ "- 提示:from sklearn.svm import SVC('Gender') "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 23,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Accuracy: 0.9317073170731708\n"
+ ]
+ },
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ }
+ ],
+ "source": [
+ "from sklearn.svm import SVC\n",
+ "model = SVC(random_state=42)\n",
+ "model.fit(X_train, y_train)\n",
+ "y_pred = model.predict(X_test)\n",
+ "accuracy = accuracy_score(y_test, y_pred)\n",
+ "print(\"Accuracy:\", accuracy)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### KNN\n",
+ "- 提示:from sklearn.neighbors import KNeighborsClassifier('Gender') "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 15,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Accuracy: 0.9267832489645651\n"
+ ]
+ },
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ }
+ ],
+ "source": [
+ "from sklearn.neighbors import KNeighborsClassifier\n",
+ "model = KNeighborsClassifier(3)\n",
+ "model.fit(X_train, y_train)\n",
+ "y_pred = model.predict(X_test)\n",
+ "accuracy = accuracy_score(y_test, y_pred)\n",
+ "print(\"Accuracy:\", accuracy)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "---\n",
+ "\n",
+ "## 练习3:在测试集上进行预测,计算准确度"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Logistic regression\n",
+ "- 提示:y_pred_LR = clf_LR.predict(x_test)('Gender') "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 16,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [],
+ "source": [
+ "from sklearn.linear_model import LogisticRegression\n",
+ "from sklearn.metrics import accuracy_score\n",
+ "model = LogisticRegression()\n",
+ "model.fit(X_train, y_train)\n",
+ "y_pred = model.predict(X_test)\n",
+ "accuracy = accuracy_score(y_test, y_pred)\n",
+ "print(\"Accuracy:\", accuracy)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Decision Tree\n",
+ "- 提示:y_pred_tree = tree.predict(x_test)('Gender') "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 17,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [],
+ "source": [
+ "from sklearn.tree import DecisionTreeClassifier\n",
+ "model = DecisionTreeClassifier(random_state=42)\n",
+ "model.fit(X_train, y_train)\n",
+ "y_pred = model.predict(X_test)\n",
+ "accuracy = accuracy_score(y_test, y_pred)\n",
+ "print(\"Accuracy:\", accuracy)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Random Forest\n",
+ "- 提示:y_pred_forest = forest.predict(x_test)('Gender') "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [],
+ "source": [
+ "from sklearn.ensemble import RandomForestClassifier\n",
+ "model =RandomForestClassifier(random_state=42)\n",
+ "model.fit(X_train, y_train)\n",
+ "y_pred = model.predict(X_test)\n",
+ "accuracy = accuracy_score(y_test, y_pred)\n",
+ "print(\"Accuracy:\", accuracy)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### SVM\n",
+ "- 提示:y_pred_SVC = clf_svc.predict(x_test)('Gender') "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [],
+ "source": [
+ "from sklearn.svm import SVC\n",
+ "model = SVC(random_state=42)\n",
+ "model.fit(X_train, y_train)\n",
+ "y_pred = model.predict(X_test)\n",
+ "accuracy = accuracy_score(y_test, y_pred)\n",
+ "print(\"Accuracy:\", accuracy)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### KNN\n",
+ "- 提示:y_pred_KNN = neigh.predict(x_test)('Gender') "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 20,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [],
+ "source": [
+ "from sklearn.neighbors import KNeighborsClassifier\n",
+ "model = KNeighborsClassifier(3)\n",
+ "model.fit(X_train, y_train)\n",
+ "y_pred = model.predict(X_test)\n",
+ "accuracy = accuracy_score(y_test, y_pred)\n",
+ "print(\"Accuracy:\", accuracy)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "---\n",
+ "## 练习4:查看sklearn的官方说明,了解分类问题的评估标准,并对此例进行评估"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "**混淆矩阵(Confusion Matrix)相关学习链接**\n",
+ "\n",
+ "- Blog: \n",
+ "http://blog.csdn.net/vesper305/article/details/44927047 \n",
+ "- WiKi: \n",
+ "http://en.wikipedia.org/wiki/Confusion_matrix \n",
+ "- sklearn doc: \n",
+ "http://scikit-learn.org/stable/modules/generated/sklearn.metrics.confusion_matrix.html"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 25,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Accuracy: 0.9267832489645651\n"
+ ]
+ },
+ {
+ "data": {
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAi8AAAHFCAYAAAA64xk9AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy81sbWrAAAACXBIWXMAAA9hAAAPYQGoP6dpAAArHklEQVR4nO3deViVdf7/8dcRWUVQwA0C1zS0UsQ0LXO3yEzGJi0tRRFzqbSMHHMUzUrl24yWua9pjss3l1FLv1naZpi7pZEz5oKWjFtqIhLL/fvDn2c8AnqQg/Ch5+O6uGbOfd/nvt83V+az+9znHJtlWZYAAAAMUaa4BwAAACgI4gUAABiFeAEAAEYhXgAAgFGIFwAAYBTiBQAAGIV4AQAARiFeAACAUYgXAABgFOIFMMB3332nPn36qGbNmvLy8pKvr68aN26sxMREnT17tkiPvXv3brVq1Ur+/v6y2WyaPHmyy49hs9k0ZswYl+/3ZhYsWCCbzSabzabPP/8813rLslSnTh3ZbDa1bt36lo4xbdo0LViwoEDP+fzzz/OdCYBUtrgHAHBjs2fP1qBBg1SvXj3Fx8erfv36yszM1I4dOzRjxgwlJSVp1apVRXb8vn37Ki0tTUuXLlXFihVVo0YNlx8jKSlJd9xxh8v366zy5ctr7ty5uQLliy++0E8//aTy5cvf8r6nTZumoKAgxcTEOP2cxo0bKykpSfXr17/l4wKlGfEClGBJSUkaOHCgOnTooNWrV8vT09O+rkOHDho2bJg2bNhQpDPs27dPcXFxioqKKrJj3H///UW2b2d0795dixcv1tSpU+Xn52dfPnfuXDVv3lwXLly4LXNkZmbKZrPJz8+v2H8nQEnGy0ZACfbWW2/JZrNp1qxZDuFylYeHhx5//HH745ycHCUmJuquu+6Sp6enKleurF69eun48eMOz2vdurXuvvtubd++XS1btpSPj49q1aqlCRMmKCcnR9J/X1LJysrS9OnT7S+vSNKYMWPs//9aV59z5MgR+7JNmzapdevWCgwMlLe3t8LCwvTEE0/o0qVL9m3yetlo37596tKliypWrCgvLy81atRI77//vsM2V19eWbJkiUaOHKng4GD5+fmpffv2OnDggHO/ZElPP/20JGnJkiX2ZefPn9eKFSvUt2/fPJ8zduxYNWvWTAEBAfLz81Pjxo01d+5cXftdtzVq1ND+/fv1xRdf2H9/V69cXZ190aJFGjZsmEJCQuTp6amDBw/metno9OnTCg0NVYsWLZSZmWnf/w8//KBy5crp2WefdfpcgdKAeAFKqOzsbG3atEmRkZEKDQ116jkDBw7U8OHD1aFDB61Zs0bjxo3Thg0b1KJFC50+fdph29TUVPXs2VPPPPOM1qxZo6ioKI0YMUIffPCBJKlTp05KSkqSJP35z39WUlKS/bGzjhw5ok6dOsnDw0Pz5s3Thg0bNGHCBJUrV06///57vs87cOCAWrRoof379+vdd9/VypUrVb9+fcXExCgxMTHX9q+99pqOHj2qOXPmaNasWfr3v/+tzp07Kzs726k5/fz89Oc//1nz5s2zL1uyZInKlCmj7t2753tuzz33nJYvX66VK1eqa9eueuGFFzRu3Dj7NqtWrVKtWrUUERFh//1d/xLfiBEjlJKSohkzZmjt2rWqXLlyrmMFBQVp6dKl2r59u4YPHy5JunTpkp588kmFhYVpxowZTp0nUGpYAEqk1NRUS5L11FNPObV9cnKyJckaNGiQw/Jvv/3WkmS99tpr9mWtWrWyJFn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ZUVFSUUlJSins0AIWQlpamhg0b6r333ivuUVBC8VZpGKtZs2Zq3Lixpk+fbl8WHh6u6OhojR8/vhgnA+AqNptNq1atUnR0dHGPghKEKy8w0u+//66dO3eqY8eODss7duyob775ppimAgDcDsQLjHT69GllZ2erSpUqDsurVKmi1NTUYpoKAHA7EC8wms1mc3hsWVauZQCA0oV4gZGCgoLk5uaW6yrLyZMnc12NAQCULsQLjOTh4aHIyEht3LjRYfnGjRvVokWLYpoKAHA7lC3uAYBb9fLLL+vZZ59VkyZN1Lx5c82aNUspKSkaMGBAcY8GoBAuXryogwcP2h8fPnxYe/bsUUBAgMLCwopxMpQUvFUaRps2bZoSExN14sQJ3X333Zo0aZIeeuih4h4LQCF8/vnnatOmTa7lvXv31oIFC27/QChxiBcAAGAU7nkBAABGIV4AAIBRiBcAAGAU4gUAABiFeAEAAEYhXgAAgFGIFwAAYBTiBcAtGzNmjBo1amR/HBMTo+jo6Ns+x5EjR2Sz2bRnz54iO8b153orbsecwB8B8QKUMjExMbLZbLLZbHJ3d1etWrX0yiuvKC0trciP/c477zj9Cai3+y/y1q1ba+jQobflWACKFt9tBJRCjzzyiObPn6/MzEx99dVX6tevn9LS0jR9+vRc22ZmZsrd3d0lx/X393fJfgDgRrjyApRCnp6eqlq1qkJDQ9WjRw/17NlTq1evlvTflz/mzZunWrVqydPTU5Zl6fz58+rfv78qV64sPz8/tW3bVnv37nXY74QJE1SlShWVL19esbGxunz5ssP66182ysnJ0cSJE1WnTh15enoqLCxMb775piSpZs2akqSIiAjZbDa1bt3a/rz58+crPDxcXl5euuuuuzRt2jSH42zbtk0RERHy8vJSkyZNtHv37kL/zoYPH666devKx8dHtWrV0qhRo5SZmZlru5kzZyo0NFQ+Pj568sknde7cOYf1N5v9Wr/++qt69uypSpUqydvbW3feeafmz59f6HMBSjuuvAB/AN7e3g5/ER88eFDLly/XihUr5ObmJknq1KmTAgIC9PHHH8vf318zZ85Uu3bt9K9//UsBAQFavny5EhISNHXqVLVs2VK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j0t2drZ9WZUqVRQSEqJDhw6pZ8+eee63fv36WrRokdLT0+2BdKM5nLFlyxZVr15dI0eOtC87evRoru1SUlL0yy+/KDg4WJKUlJSkMmXKqG7duk7NnpdKlSopJiZGMTExatmypeLj44kX4CaIFwBq3769mjdvrujoaE2cOFH16tXTL7/8oo8//ljR0dFq0qSJhgwZot69e6tJkyZ68MEHtXjxYu3fvz/fG3a9vLw0fPhwvfrqq/Lw8NADDzygU6dOaf/+/YqNjVXlypXl7e2tDRs26I477pCXl5f8/f01ZswYvfjii/Lz81NUVJQyMjK0Y8cO/frrr3r55ZfVo0cPjRw5UrGxsfrrX/+qI0eOOP2X/alTp3J9rkzVqlVVp04dpaSkaOnSpbrvvvv00UcfadWqVXmeU+/evfX222/rwoULevHFF9WtWzdVrVpVkm46+/VGjx6tyMhINWjQQBkZGVq3bp3Cw8OdOhfgD624b7oB4FrX37B7vYSEBIebbK+6cOGC9cILL1jBwcGWu7u7FRoaavXs2dNKSUmxb/Pmm29aQUFBlq+vr9W7d2/r1VdfzfeGXcuyrOzsbOuNN96wqlevbrm7u1thYWHWW2+9ZV8/e/ZsKzQ01CpTpozVqlUr+/LFixdbjRo1sjw8PKyKFStaDz30kLVy5Ur7+qSkJKthw4aWh4eH1ahRI2vFihVO3bArKddPQkKCZVmWFR8fbwUGBlq+vr5W9+7drUmTJln+/v65fm/Tpk2zgoODLS8vL6tr167W2bNnHY5zo9mvv2F33LhxVnh4uOXt7W0FBARYXbp0sQ4dOpTvOQC4wmZZRfACMgAAQBHhQ+oAAIBRiBcAAGAU4gUAABiFeAEAAEYhXgAAgFGIFwAAYBTiBQAAGIV4AQAARiFeAACAUYgXAABgFOIFAAAYhXgBAABG+X9xfnFfJNSA0QAAAABJRU5ErkJggg==",
+ "text/plain": [
+ ""
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
+ "source": [
+ "from sklearn.neighbors import KNeighborsClassifier\n",
+ "from sklearn.metrics import confusion_matrix\n",
+ "import seaborn as sns\n",
+ "import matplotlib.pyplot as plt\n",
+ "model = KNeighborsClassifier(3)\n",
+ "model.fit(X_train, y_train)\n",
+ "y_pred = model.predict(X_test)\n",
+ "accuracy = accuracy_score(y_test, y_pred)\n",
+ "print(\"Accuracy:\", accuracy)\n",
+ "conf_matrix = confusion_matrix(y_test, y_pred)\n",
+ "sns.heatmap(conf_matrix, annot=True, fmt=\"d\", cmap=\"Blues\", cbar=False)\n",
+ "plt.title(\"Confusion Matrix\")\n",
+ "plt.xlabel(\"Predicted Labels\")\n",
+ "plt.ylabel(\"True Labels\")\n",
+ "plt.show()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## 练习5:调整模型的标准\n",
+ "\n",
+ "银行通常会有更严格的要求,因为fraud带来的后果通常比较严重,一般我们会调整模型的标准。 \n",
+ "\n",
+ "比如在logistic regression当中,一般我们的概率判定边界为0.5,但是我们可以把阈值设定低一些,来提高模型的“敏感度”,试试看把阈值设定为0.3,再看看这时的评估指标(主要是准确率和召回率)。\n",
+ "\n",
+ "- 提示:sklearn的很多分类模型,predict_prob可以拿到预估的概率,可以根据它和设定的阈值大小去判断最终结果(分类类别)('Gender') "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 26,
+ "metadata": {
+ "jupyter": {
+ "outputs_hidden": true
+ }
+ },
+ "outputs": [
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ },
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "Accuracy: 0.9307\n",
+ "Precision: 0.4409\n",
+ "Recall: 0.0553\n"
+ ]
+ },
+ {
+ "name": "stderr",
+ "output_type": "stream",
+ "text": [
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\linear_model\\_logistic.py:458: ConvergenceWarning: lbfgs failed to converge (status=1):\n",
+ "STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.\n",
+ "\n",
+ "Increase the number of iterations (max_iter) or scale the data as shown in:\n",
+ " https://scikit-learn.org/stable/modules/preprocessing.html\n",
+ "Please also refer to the documentation for alternative solver options:\n",
+ " https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression\n",
+ " n_iter_i = _check_optimize_result(\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:767: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if not hasattr(array, \"sparse\") and array.dtypes.apply(is_sparse).any():\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:605: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype):\n",
+ "D:\\Anaconda\\envs\\taiji\\Lib\\site-packages\\sklearn\\utils\\validation.py:614: FutureWarning: is_sparse is deprecated and will be removed in a future version. Check `isinstance(dtype, pd.SparseDtype)` instead.\n",
+ " if is_sparse(pd_dtype) or not is_extension_array_dtype(pd_dtype):\n"
+ ]
+ }
+ ],
+ "source": [
+ "from sklearn.model_selection import train_test_split\n",
+ "from sklearn.linear_model import LogisticRegression\n",
+ "from sklearn.metrics import accuracy_score, precision_score, recall_score\n",
+ "import numpy as np\n",
+ "\n",
+ "# Split the data into training and testing sets\n",
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n",
+ "\n",
+ "# Instantiate the logistic regression model\n",
+ "model = LogisticRegression()\n",
+ "\n",
+ "# Train the model on the training data\n",
+ "model.fit(X_train, y_train)\n",
+ "\n",
+ "# Set a lower threshold for classification\n",
+ "threshold = 0.3\n",
+ "y_prob = model.predict_proba(X_test)[:, 1] # Get the probabilities of the positive class\n",
+ "y_pred_lower_threshold = (y_prob >= threshold).astype(int)\n",
+ "\n",
+ "# Evaluate the model's performance with the lower threshold\n",
+ "accuracy = accuracy_score(y_test, y_pred_lower_threshold)\n",
+ "precision = precision_score(y_test, y_pred_lower_threshold)\n",
+ "recall = recall_score(y_test, y_pred_lower_threshold)\n",
+ "\n",
+ "print(f\"Accuracy: {accuracy:.4f}\")\n",
+ "print(f\"Precision: {precision:.4f}\")\n",
+ "print(f\"Recall: {recall:.4f}\")"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "taiji",
+ "language": "python",
+ "name": "taiji"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.11.5"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}