day 33打卡

python 复制代码
day 21
常见的降维算法
# 先运行之前预处理好的代码
import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')

# 设置中文字体
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
data=pd.read_csv('/Users/gj/东财-学习/python相关资料学习/Python60DaysChallenge-main/data.csv')
# 先筛选字符串变量
discrete_features=data.select_dtypes(include=['object']).columns.to_list()
# Home Ownership 变量
home_ownership_mapping={
    'Own Home':1,
    'Rent':2,
    'Have Mortgage':3,
    'Home Mortgage':4
}
data['Home Ownership']=data['Home Ownership'].map(home_ownership_mapping)
# Years in current job 变量
years_in_job_mapping={
    '<1 year':1,
    '1 year':2,
    '2 years':3,
    '3 years':4,
    '4 years':5,
    '5 years':6,
    '6 years':7,
    '7 years':8,
    '8 years':9,
    '9 years':10,
    '10+ years':11
}
data=pd.get_dummies(data,columns=['Purpose'])
data2=pd.read_csv('/Users/gj/东财-学习/python相关资料学习/Python60DaysChallenge-main/data.csv')
list_final=[]
for i in data.columns:
    if i  not in data2.columns:
        list_final.append(i)
for i in list_final:
    data[i]=data[i].astype(int)

# term 0-1 映射
term_mapping={
    'Short Term':0,
    'Long Term':1
}
data['Term']=data['Term'].map(term_mapping)
data.rename(columns={'Term':'Long Term'},inplace=True)
continuous_features=data.select_dtypes(include=['int64','float64']).columns.to_list()
# 连续特征用中位数
for feat in continuous_features:
    mode_value=data[feat].mode()[0]
    data[feat].fillna(mode_value,inplace=True)

# 最开始也说了,很多调参数自带交叉验证,甚至是必选的参数,你如果想要不交叉更麻烦
data.drop(columns=['Id'],inplace=True)
data.info()
特征降维
通常情况下,提到降维,很多时候默认指的是无监督降维,这种方法只需要特征数据本身。但是实际上还包含一种有监督的方法。
1、无监督降维:
定义:这类算法在降维过程中不使用任何关于数据样本的标签信息(比如类别标签、目标值等)。他们仅仅根据数据点本身的分布,方差、相关性、局部结构等特性来寻找低维表示。
输入:只有特征矩阵X
目标:
保留数据中尽可能多的方差(如PCA)
保留数据的局部或全局流型结构(如LLE,LSOMAP,t-SNE,UMAP)
找到能够有效重构原始数据的紧凑表示()
2、有监督降维:
定义:这类算法在降维过程中利用标签信息来指导降维过程。例如,在分类问题中,我们可能希望将不同类别的样本映射到低维空间,同时保持类别之间的区分度。
输入:特征矩阵X和对应的标签y
目标:
在低维空间中保留类别之间的区分度(如LDA)   

最近工作上有点忙,可能每天学习的东西有限了,后面补上

@浙大疏锦行

相关推荐
test管家1 天前
PyTorch动态图编程与自定义网络层实战教程
python
laocooon5238578861 天前
python 收发信的功能。
开发语言·python
清水白石0081 天前
《Python 责任链模式实战指南:从设计思想到工程落地》
开发语言·python·责任链模式
沛沛老爹1 天前
Web开发者快速上手AI Agent:基于LangChain的提示词应用优化实战
人工智能·python·langchain·提示词·rag·web转型
宁大小白1 天前
pythonstudy Day39
python·机器学习
拾贰_C1 天前
【VSCode | python | anaconda | cmd | PowerShell】在没有进入conda环境时使用conda命令默认安装位置
vscode·python·conda
大千AI助手1 天前
基于OpenAPI生成的 SDK 的工业级和消费级概念区别
人工智能·python·机器学习·openai·代码生成·openapi·大千ai助手
骚戴1 天前
n1n:从替代LiteLLM Proxy自建网关到企业级统一架构的进阶之路
人工智能·python·大模型·llm·gateway·api
秋氘渔1 天前
智演沙盘 —— 基于大模型的智能面试评估系统
python·mysql·django·drf
爱笑的眼睛111 天前
超越AdamW:优化器算法的深度实现、演进与自定义框架设计
java·人工智能·python·ai