Data Mining
Data Mining and Machine Learning
爱上这个夏天
这个作者很懒,什么都没留下…
展开
-
PCA算法数据降维
sklearn.decomposition.PCA参数介绍下面我们主要基于sklearn.decomposition.PCA来讲解如何使用scikit-learn进行PCA降维。PCA类基本不需要调参,一般来说,我们只需要指定我们需要降维到的维度,或者我们希望降维后的主成分的方差和占原始维度所有特征方差和的比例阈值就可以了。现在我们对sklearn.decomposition.PCA的主要参数做一个介绍:1)n_components:这个参数可以帮我们指定希望PCA降维后的特征维度数目。最常用的做法是转载 2021-10-16 16:14:35 · 1339 阅读 · 0 评论 -
matpltliab 多子图
怎么在一个图上排列多个子图?比如说我们想画个2*2的子图,每个子图对应一个表。import pandas as pdimport numpy as npimport matplotlib.pyplot as plt fig, axes = plt.subplots(2, 2) data = pd.Series(np.random.rand(16), index=list('abcdefghijklmnop')) data.plot.bar(ax=axes[1,1], color='b',转载 2021-09-22 07:57:03 · 154 阅读 · 0 评论 -
Matplotlib 常用命令
import matplotlib.pyplot as pltplt.title('折线图标题',fontsize=22) #标题,更改字体大小ax.set_xlabel('X轴',fontsize=18) #设置x轴,y轴的标题ax.set_ylabel('Y轴',fontsize=18)plt.yticks(fontsize=14) #刻度字体大小plt.xticks(fontsize=14)fig, (ax1, ax2) = plt.subplots(1, 2) #输出1行x2列的图原创 2021-09-22 07:47:18 · 433 阅读 · 0 评论 -
Matplotlib柱状图 - plt.bar()、plt.barh()
一、plt.bar()、plt.barh()参数详解简介:plt.bar():正常柱状图????????,常见的统计图;plt.barh():横向的柱状图,可以理解为正常柱状图旋转了90°。import matplotlib as mplimport matplotlib.pyplot as pltfrom matplotlib.pyplot import MultipleLocatorfrom matplotlib import ticker%matplotlib inlineplt转载 2021-09-14 09:13:40 · 9969 阅读 · 0 评论 -
sklearn.datasets中的make_blobs函数解析
sklearn.datasets中的make_blobs函数在机器学习生成数据集以自建模型中应用广泛,此文就其格式及参数设置说明如下:函数格式及默认参数设置sklearn.datasets.make_blobs(n_samples=100, n_features=2, centers=None, cluster_std=1.0, center_box=(-10.0, 10.0), shuffle=True, random_state=None)函数功能生成各向同性的高斯斑点以进行聚类。参数n_s转载 2021-09-13 16:07:05 · 563 阅读 · 0 评论 -
Matplotlib Unknown property facecolor||‘Line2D‘ object has no property ‘facecolor‘的解决办法
‘Line2D’ object has no property ‘facecolor’,boxplot函数是有一个patch_artist参数的,于是加了个patch_artist=True于是问题就解决了。转载 2021-09-05 15:22:54 · 859 阅读 · 0 评论 -
Python数据分析:特征选择-SelectKBest
一、参数:SelectKBest(score_func= f_classif, k=10)score_func:特征选择要使用的方法,默认适合分类问题的F检验分类:f_classif。k :取得分最高的前k个特征,默认10个。二、属性:fit(x,y)方法后才能调用scores_ :返回每个特征的得分pvalues_ : 返回每个特征得分对应的p_value值。如果score_func只返回分数,则pvalues_返回空。三、常用方法fit(x,y):传入特征集x和标签y 拟合数据。tran转载 2021-09-03 09:47:33 · 13517 阅读 · 0 评论 -
matplotlib绘制饼图
pie(x, explode=None, labels=None, colors=None, autopct=None, pctdistance=0.6, labeldistance=1.1)x:指定绘图的数据 explode:指定饼图某些部分的突出显示,即呈现爆炸式labels:为饼图添加标签说明,类似于图例说明 colors:指定饼图的填充色 autopct:自动添加百分比显示,可以采用格式化的方法显示 pctdistance:设置百分比标签与圆心的距离 labeldistance:设置各扇形标签(原创 2021-08-27 17:30:50 · 248 阅读 · 0 评论 -
LabelEncoder 的使用
作用:将离散型的数据转换成 0 00 到 n − 1 n-1n−1 之间的数,这里 n nn 是一个列表的不同取值的个数,可以认为是某个特征的所有不同取值的个数。from sklearn.preprocessing import LabelEncoderdata = pd.read_csv(pathUtils.train_path,engine='python')encoder= LabelEncoder().fit(data["job"])data["job"] = encoder.transfo转载 2021-08-23 08:34:14 · 12153 阅读 · 2 评论 -
特征选择的几种方法
1、 过滤法(Filter)1.1 方差选择法 使用方差选择法,先要计算各个特征的方差,然后根据阈值,选择方差大于阈值的特征。使用feature_selection库的VarianceThreshold类来选择特征的代码如下:from sklearn.feature_selection import VarianceThreshold #方差选择法,返回值为特征选择后的数据#参数threshold为方差的阈值VarianceThreshold(threshold=3).fit_tran转载 2021-08-17 15:51:32 · 3334 阅读 · 0 评论 -
使用tweepy 统计twitter数据
安装:pip install tweepy#导入tweepy import tweepy #填写twitter提供的开发Key和secret consumer_key = 'xxxxxxxxxxxxxxxxx' consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxx' access_token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' access_token_secret = 'xxxxxxxxxxx原创 2021-08-17 09:30:25 · 499 阅读 · 0 评论 -
报错ConvergenceWarning: Stochastic Optimizer: Maximum iterations (200) reached and the optimization ha
执行下面代码出现报错: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (200) reached and the optimization hasn’t converged yet. warnings.warn(clf = MLPClassifier()clf.fit(pred_train, np.ravel(tar_train, order='C'))predictions = clf.predict(pred_test原创 2021-08-08 18:11:53 · 5806 阅读 · 0 评论 -
set_xticks和set_xticklabels的组合用法
import matplotlib.pyplot as pltfrom scipy import randnfigure = plt.figure(); ax1 = figure.add_subplot(2,2,3) # 绘制图表(2,2,3)表示图形应该是2 x 2的,且当前选择的是4个subplot 中的第三个ax2 = figure.add_subplot(2,2,4)ax1.plot(randn(1000).cumsum()) # 绘制图形ax2.plot(randn(180).cum.转载 2021-07-28 17:10:33 · 4929 阅读 · 0 评论 -
boxplot箱线图
plt.boxplot(x, notch=None, sym=None, vert=None, whis=None, positions=None, widths=None, patch_artist=None, meanline=None, showmeans=None, showcaps=None, showbox=None, showfliers=None, boxprops=None, l转载 2021-07-28 17:07:07 · 441 阅读 · 0 评论 -
add_subplot(self, *args, **kwargs)添加子图
add_subplot(self, *args, **kwargs)添加子图The first argument is the number of plots in each row and the second the number of plots per columnthe last argument should small than the total numberadd_subplot(1,3,2) 等同于 add_subplot(132)如出现报错:add_subplot原创 2021-07-28 17:02:33 · 170 阅读 · 0 评论 -
figure语法及操作
figure语法及操作(1)figure语法说明figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True)num:图像编号或名称,数字为编号 ,字符串为名称figsize:指定figure的宽和高,单位为英寸;dpi参数指定绘图对象的分辨率,即每英寸多少个像素,缺省值为80 1英寸等于2.5cm,A4纸是 21*30cm的纸张facecolor:背景颜色edgecolor转载 2021-07-28 16:37:27 · 495 阅读 · 0 评论 -
散点图矩阵 pd.plotting.scatter_matrix
pd.plotting.scatter_matrix(frame, alpha=0.5, c,figsize=None, ax=None, diagonal=‘hist’, marker=’.’, density_kwds=None,hist_kwds=None, range_padding=0.05, **kwds)1、frame,pandas dataframe对象2、alpha, 图像透明度,一般取(0,1]3、figsize,以英寸为单位的图像大小,一般以元组 (width, height)转载 2021-07-28 16:36:47 · 1085 阅读 · 0 评论 -
pandas 常用命令
创建数据框pd.DataFramepd.locpd.ilocpd.sort_values()pd.read_csvpd.read_excel在不同数据类型间转换df.astype(dtype : 指定希望转换的数据类型可以使用numpy或者python中的数据类型: int/float/bool/strcopy = True : 是否生成新的副本,而不是替换原数据框errors = ‘raise’ : 转换出错时是否抛出错误,‘raise’/‘ignore’)保存数据到外部文件原创 2021-07-06 19:00:32 · 425 阅读 · 0 评论 -
PYTHON MATPLOTLIB绘制图例 报错LEGEND DOES NOT SUPPORT []
import matplotlib.pyplot as pltx_data = ['2011', '2012', '2013', '2014', '2015']y_data = [58000, 60000, 51000, 40000, 80000]y_data2 = [81000,53000, 65000, 77000, 90000]ln1 = plt.plot(x_data, y_data, color = 'green')ln2 = plt.plot(x_data, y_data2, colo转载 2021-07-28 08:43:57 · 876 阅读 · 2 评论 -
sklearn 常用命令
在机器学习中,我们通常将原始数据按照比例分割为“测试集”和“训练集”,通常使用sklearn.model_selection 中调用train_test_split 函数train_test_split()是sklearn包的model_selection模块中提供的随机划分训练集和测试集的函数;使用train_test_split函数可以将原始数据集按照一定比例划分训练集和测试集对模型进行训练x,y是原始的数据集。X_train,y_train 是原始数据集划分出来作为训练模型的,fit模型的时候用。转载 2021-07-25 13:34:04 · 354 阅读 · 0 评论 -
numpy常用命令
np.unique. 该函数是去除数组中的重复数字,并进行排序之后输出。原创 2021-07-25 12:52:08 · 149 阅读 · 0 评论 -
matplotlib折线图/直方图
折线图import matplotlib.pyplot as pltimport numpy as np#line plots#createdataN=100x_data=np.random.rand(N)y_data=np.random.rand(N)def lineplot(x_data, y_data, x_label="", y_label="", title=""): #create the plot object _, ax = plt.subplots()原创 2021-07-25 12:02:23 · 252 阅读 · 0 评论 -
散点图scatter plot
import matplotlib.pyplot as pltimport numpy as np#createdataN = 100#np.random.rand(x,y) 其中x代表行,y代表列,如果只有一个参数,默认是列#返回1行N列服从“0~1”均匀分布的随机样本值,随机样本取值范围是[0,1),不包括1。 x_data = np.random.rand(N)print(x_data)y_data = np.random.rand(N)def scatter_plot(原创 2021-07-25 11:37:19 · 569 阅读 · 0 评论