個人學習之作,水平有限,僅供參考,與諸君共勉。
1:目的
調用庫,熟悉數據清洗,數據處理,熟悉python的編程知識
大概流程如下(建議熟記,對知識的掌握和麪試都是有好處的):
-
確保數據集本身是可用的,包括但不限於:
a) 檢查數據本身是否平衡(balanced or not),並處理
b) 檢查數據本身是否有缺失值 (missing value),並處理
c) 檢查數據本身是否有一些明顯的異類數據(outlier), 根據情況再做處理 -
檢查數據集本身特質,確定適合的機器學習模型(machine learning model)
a) 有監督模型(Supervised) VS 無監督模型(Unsupervised)
b) 迴歸模型(Regression) VS 分類模型(Classification) -
通過數據可視化,建立一個對於數據集的直覺(intuition)和認知(understanding)
-
通過數據可視化,大致瞭解特徵與結果之間的聯繫,進一步確定適合的機器學習模型
-
預測並驗證未來模型產出的結果
-
對用在模型中的特徵做初步的篩選
-
爲特徵工程(feature engineering)部分做準備
2: 數據
數據csv大概如下:我會上傳到下載那塊,有需求的朋友自己下載
3:開始
# 引入庫包
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv('student-por.csv')
在引入庫包之後,進行初步的數據處理
print(df.head(10))
print(df.shape)
print(df.isnull().sum())
print(df.describe(include = 'all'))
print(df.info())
重點說一下,這個數據集比較乾淨,也無任何缺省,
數據段中文對應關係如下
字段名 | 含義 | 類型 | 描述 |
---|---|---|---|
sex | 性別 | string | F是女,M表示男 |
address | 住址 | string | U表示城市,R表示鄉村 |
famsize | 家庭成員數 | string | LE3表示少於三人,GT3多於三人 |
pstatus | 是否與父母住在一起 | string | T住在一起,A分開 |
medu | 母親的文化水平 | string | 從0~4逐步增高 |
fedu | 父親的文化水平 | string | 從0~4逐步增高 |
mjob | 母親的工作 | string | 分爲教師相關、健康相關、服務業 |
fjob | 父親的工作 | string | 分爲教師相關、健康相關、服務業 |
guardian | 學生的監管人 | string | mother,father or other |
traveltime | 從家到學校需要的時間 | double | 以分鐘爲單位 |
studytime | 每週學習時間 | double | 以小時爲單位 |
failures | 掛科數 | double | 掛科次數 |
schoolsup | 是否有額外的學習輔助 | string | yes or no |
fumsup | 是否有家教 | string | yes or no |
paid | 是否有相關考試學科的輔助 | string | yes or no |
activities | 是否有課外興趣班 | string | yes or no |
higher | 是否有向上求學意願 | string | yes or no |
internet | 家裏是否聯網 | string | yes or no |
famrel | 家庭關係 | double | 從1~5表示關係從差到好 |
freetime | 課餘時間量 | double | 從1~5從少到多 |
goout | 跟朋友出去玩的頻率 | double | 從1~5從少到多 |
dalc | 日飲酒量 | double | 從1~5從少到多 |
walc | 周飲酒量 | double | 從1~5從少到多 |
health | 健康狀況 | double | 從1~5從狀態差到好 |
absences | 出勤量 | double | 0到93次 |
G1,G2,G3 | 期末成績 | double | 20分制 |
1;對性別進行處理
sns.countplot(x = 'sex', order = ['M','F'], data = df )
df['sex'].replace('M','0')
df['sex'].replace('F','1')
將M-男,F-女 轉化爲01
2:對地址進行轉換
sns.countplot(x = 'address', order = ['U','R'], data = df )
df['address'].replace('U','1')
df['address'].replace('R','0')
Reference:
1:https://tianchi.aliyun.com/course/video?spm=5176.12282042.0.0.3eb22042bd6YRi&liveId=7729
1:https://tianchi.aliyun.com/notebook-ai/detail?spm=5176.12281897.0.0.209439a9IUXP6k&postId=7459
1:https://blog.csdn.net/jiangtianshe/article/details/77703450