![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
无穷QQ君
When nothing is sure, everything is possible. It can be done.
展开
-
sklearn 回归问题的评估指标
1.Root mean square error (RMSE):2.Mean absolute error(MAE):3.R-Square ($R^2$):4.Median Absolute Deviation (MAD):##########导入sklearn工具包##########from sklearn import metricsRMSE = np.sqrt(mean_squared_error(y_true, y_predict))MAE=...原创 2021-10-02 18:31:44 · 550 阅读 · 0 评论 -
DeprecationWarning: `np.float` is a deprecated;Deprecated in NumPy 1.20
解决方法:升级numpy版本conda update scikit-learn原创 2021-09-24 17:22:42 · 1749 阅读 · 0 评论 -
集成学习与深度学习 加载模型方法
1. 集成学习import joblibjoblib.load("model.pkl")2.深度学习用torch自带的load()import torchdata = torch.load("model.pkl")error:pickle.UnpicklingError: A load persistent id instruction was encountered,but no persistent_load function was specified...原创 2021-08-10 11:15:05 · 742 阅读 · 0 评论 -
matplotlib 双y轴公用一个x轴
目录1. legend 控制2. 线条控制线条类型:线条粗细:3. 透明度控制完整栗子1:完整栗子2:1. legend 控制功能:将图例放在图的外面# legend fig.legend(bbox_to_anchor=(0,1.02,1,0.2), loc="lower center", mode="expand", borderaxespad=1, ncol=3,fontsize=20)bbox_to_ancho.原创 2021-08-06 14:56:43 · 1242 阅读 · 1 评论 -
Python 列表中的NAN替换为0
import mathmylist = [0 if math.isnan(x) else x for x in mylist]replace the NaN value zero after an operation with arrays原创 2021-08-06 14:35:51 · 6672 阅读 · 1 评论 -
sns.heatmap 控制参数
cbar水平横放将x轴刻度放置在top位置的几种方法自定义x轴、y轴标签:xticklabels、yticklabels图例位置、名称、标签等设置:cbar_kws原创 2021-07-21 22:10:46 · 1652 阅读 · 0 评论 -
numpy.polyfit:LinAlgError: SVD did not converge in Linear Least Squares
原因:有NAN值解决方法:去除NAN值,例如去除a,b,c列中有NAN值的行data = data.dropna(axis=0,subset=['a', 'b','c'])reference:删除DataFrame中某列值为NaN的记录/行解决在使用numpy.polyfit 时出现的 raise LinAlgError("SVD did not converge in Linear Least Squares")错误...原创 2021-07-15 15:47:24 · 6108 阅读 · 0 评论 -
Image size of 512922x322 pixels is too large. It must be less than 2^16 in each direction
plt.figure(figsize=(10,8))sns.regplot(x=data[num],y=data['Building Area Unit Price'], marker="o",ci=95, scatter_kws={"color":"b","alpha":0.2,"s":3}, fit_reg=False )#线性回归 ci=95表示95%置信区间x = data['x'].to_n.原创 2021-07-15 15:37:22 · 9124 阅读 · 3 评论 -
SHAP的理论与Python实现
1. 安装SHAPpip 安装:pip install shapconda 安装:conda install -c conda-forge shap2.理论与Python实现 -------------后续更新,敬请等待!原创 2021-05-10 22:05:48 · 1218 阅读 · 4 评论 -
pandas.DataFrame.groupby 按某列类型值将文件分为多个文件
1.groupby()pandas.DataFrame.groupby()groupby函数使用映射器或一系列列对数据帧进行分组。groupby操作涉及拆分对象、应用函数和组合结果的某种组合。这可以用于对大量数据进行分组,并对这些分组进行计算操作。2.栗子groups = data.groupby(data['color']) #按“color”列的值分为多个文件#比如color列有“red, yellow, green”三个不同类型的值,则会分为red.csv; yellow..原创 2021-04-08 10:02:43 · 1576 阅读 · 3 评论 -
pandas loc函数 查看与修改特定值
df.loc[index, column_name] 选取指定行和列的数据目录1.查看同一行其他列的值2.修改特定行中其他列的值3.修改特定行的值栗子:import numpy as npimport pandas as pd df = pd.DataFrame(data = [['荔景','Kowloon'],['深井(荃灣)','New Territories'],['深井(屯門)','New Territories']],index = [1,2,3],columns原创 2021-01-20 21:26:50 · 2424 阅读 · 0 评论 -
Python 合并多个csv文件,并将文件名写入新的列
readList = [] #用来装合并文件的内容titleList = ["date","district","region"] #文件标题for i in listName: #i 是文件名#############读取多个csv文件内容################### with open('{}.csv'.format(i),'r',newline="",encoding="GB18030") as read_csvfile: readcsv_.原创 2021-01-20 13:50:57 · 3161 阅读 · 6 评论 -
Python os.path.splitext()获取去除后缀的文件名
方法:os.path.splitext()os.path.splitext() 函数将文件名和扩展名分开############导包###################import osinputfile_dir = './input' #文件路径listName = [] #存放“文件名”的列表for inputfile in os.listdir(inputfile_dir): if os.path.splitext(inputfile)[1] =原创 2021-01-20 12:35:44 · 5825 阅读 · 0 评论 -
Python replace()方法 替换多个字符串
str.replace(old, new[, max])#replace() 方法把字符串中的 old(旧字符串) 替换成 new(新字符串),如果指定第三个参数max,则替换不超过 max 次。栗子:将下列字符中的“%”与“--”去掉str.replace("%","").replace("--","")...原创 2021-01-19 14:56:10 · 7155 阅读 · 0 评论 -
Python 跳过第一行读取文件内容
方法:next()函数 next()返回迭代器的下一个项目。栗子:with open('file.csv','r',newline="",encoding="GB18030") as read_csvfile: readcsv_all = csv.reader(read_csvfile) next(read_csvfile) #跳过第一行“标题” for line in readcsv_all: ...原创 2021-01-13 21:37:25 · 1688 阅读 · 0 评论 -
pandas duplicated() 重复行标记与drop_duplicates()删除
pandas.DataFrame.duplicatedDataFrame.duplicated(subset=None,keep='first')返回表示重复行的布尔序列。Parameterssubsetcolumn label or sequence of labels, optionalOnly consider certain columns for identifying duplicates, by default use all of the columns.keep{.原创 2021-01-11 15:25:18 · 4399 阅读 · 0 评论 -
RequestsDependencyWarning: urllib3 (1.26.2) or chardet (3.0.4) doesn‘t match a supported version!
pip install requestsReference:https://stackoverflow.com/questions/56155627/requestsdependencywarning-urllib3-1-25-2-or-chardet-3-0-4-doesnt-match-a-s/56170469原创 2021-01-11 12:01:03 · 4070 阅读 · 0 评论 -
pandas groupby分组运算
pandas.DataFrame.groupby官方文档栗子:计算各地区的“建筑面积尺价”均值average_price = data_Kowloon.groupby('地區')average_price['建築面積/呎價'].mean()Reference:https://www.cnblogs.com/lemonbit/p/6810972.html...原创 2021-01-04 11:33:01 · 388 阅读 · 0 评论 -
pyecharts Map与Geo画图笔记
1.安装pyechartspip install pyecharts==0.5.112.查看pyecharts版本import pyechartspyecharts.__version__3.MapMap是实现地图区域可视化,是区域可视化.Map依赖的是额外安装的地图包,如:如果要添加经纬度坐标,只能在源文件里添加修改源文件的地区名称及坐标:栗子:香港房价地图from pyecharts import Mapdistricts1=["中..原创 2021-01-04 11:11:09 · 2247 阅读 · 5 评论 -
sklearn.preprocessing 数据预处理
目录一、标准化(Z-Score)二、归一化三、正则化一、标准化(Z-Score)公式为:(X-mean)/std 计算时对每个属性/每列分别进行。将数据按期属性(按列进行)减去其均值,并处以其方差。得到的结果是,对于每个属性/每列来说所有数据都聚集在0附近,方差为1。实现时,有两种不同的方式: 使用sklearn.preprocessing.scale()函数,可以直接将给定数据进行标准化。sklearn.preprocessing.scale 使用sklear.原创 2020-12-18 18:10:10 · 503 阅读 · 1 评论 -
pandas.date_range freq
pandas.date_range(start=None, end=None, periods=None, freq=None, tz=None, normalize=False, name=None, closed=None, **kwargs)返回固定频率的DatetimeIndex。这个函数的作用就是产生一个DatetimeIndex,就是时间序列数据的索引。Parameters:start:str or datetime-like, optionalLeft bound for gene.原创 2020-12-18 17:41:22 · 486 阅读 · 1 评论 -
pandas 缺失值处理-不同列用不同的缺失值
values = {"Longitude":114.154861,"Latitude":22.331879}data = data.fillna(value=values)原创 2020-10-12 10:37:57 · 409 阅读 · 0 评论 -
pandas 利用value_counts() 去除类别样本
目标:去除屋苑类型中样本少于100的屋苑#counts是屋苑类别个数统计counts = data['屋苑'].value_counts()# 去除数据中屋苑个数小于100的样本data = data[~data['屋苑'].isin(counts[counts < 100].index)]原创 2020-09-12 15:26:59 · 799 阅读 · 0 评论 -
‘numpy.float64‘ object is not iterable
X,y 是一个list; line是array类型,因此使用extend方法会报错。list有多中迭代添加方法,其中extend和append是最常用的,区别在于:extend添加的是一个list,而append是任何数据类型。此处只是一个value,则应该使用append方法参考:https://blog.csdn.net/Dian1pei2xiao3/article/details/90212916...原创 2020-09-09 10:51:56 · 6006 阅读 · 0 评论 -
利用“箱线图”去除异常值
#包装了一个异常值处理的代码,可以调用def outliers_proc(data, col_name, scale=3): """ 用于清洗异常值,默认box_plot(scale=3)进行清洗 param data: 接收pandas数据格式 param col_name: pandas列名 param scale: 尺度 """ def box_plot_outliers(data_ser, box_scale): .原创 2020-09-07 18:15:52 · 21113 阅读 · 9 评论 -
Python 合并多个csv文件内容;pandas.DataFrame.columns写入标题
1.合并多个csv文件内容#----------------导包----------------------import pandas as pdimport os"""inputfile_dir 是多个csv文件的目录路径outputfile 是合并内容后输出的csv文件"""inputfile_dir = ".\input" outputfile = "all.csv"for inputfile in os.listdir(inputfile_dir): print(原创 2020-07-28 14:51:34 · 1428 阅读 · 0 评论 -
机器学习算法 KNN(k-Nearest Neighbor)
目录补充:超参数和模型参数python实现:KNN(K-Nearest Neighbors) K近邻算法 实现 手写 数据集的 分类问题导入 手写数据集(digits)数据集通过上面的分析,我们可以知道,怎么将现实中的东西以数据的形式表示下面是 KNN 模型的 实例step1:将数据切分为 训练集 和测试集调用 sklearn 中的KNN算法直接调用score,...原创 2019-04-14 09:36:29 · 737 阅读 · 0 评论 -
jupyter notebook快键键
命令模式 (按键 Esc 开启)Enter: 转入编辑模式Shift-Enter: 运行本单元,选中下个单元Ctrl-Enter: 运行本单元Alt-Enter: 运行本单元,在其下插入新单元Y: 单元转入代码状态M:单元转入markdown状态 (### XXX)R: 单元转入raw状态1: 设定 1 级标题2: 设定 2 级标题3: 设定 3 级标题...原创 2019-04-07 07:26:13 · 235 阅读 · 0 评论