Historical Sales and Active Inventory kaggle
来源:互联网 发布:win10端口设置在哪里 编辑:程序博客网 时间:2024/06/07 07:11
本题数据集是来自kaggle的Historical Sales and Active Inventory数据集,该数据集包含了历史销售记录数据和当前活跃库存的数据,在原始数据集中通过FileType特征进行区分(取值分别为Historical和Active),并且在当前活跃库存数据中不存在SoldFlag和SoldCount的值,所以无法用于训练或验证模型。我们去除了当前活跃库存数据,只保留了历史销售记录数据,该数据保存了过去6个月的销售信息。
该数据集包含14个特征,目标特征为SoldFlag(取值0代表无售出,取值1代表有售出),特征SoldCount表示售出的数目,可以用于训练回归模型,在这里不符合我们分类器训练的目的,因此我们将SoldCount列删除掉。
最终数据集包含75996个样本,我们将其中的80%作为训练集(正负类均衡),剩余的20%作为测试集。
包括目标特征在内的13个特征的详细描述如下:
列名 说明 类型 示例
dataset = pd.read_csv("E:\\tianchi\\salesanalysis1\\SalesKaggle3.csv")dataset.columns=['Order','File_Type','SKU_number','SoldFlag','SoldCount','MarketingType','ReleaseNumber',\ 'New_Release_Flag','StrengthFactor','PriceReg','ReleaseYear','ItemCount','LowUserPrice','LowUserPrice']
读入文件后选出file_type为历史销售记录的。
dataset=dataset[dataset.File_Type=='Historical']dataset=dataset[['SoldFlag','Order','SKU_number','MarketingType','ReleaseNumber',\ 'New_Release_Flag','StrengthFactor','PriceReg','ReleaseYear','ItemCount','LowUserPrice','LowUserPrice']]用随机森林分类,注意这里要先把字母分类转换成01分类,另外还要注意正负样本平衡,二八比例分出测试机和训练集
from sklearn.ensemble import RandomForestClassifierimport numpy as npimport pandas as pddataset['MarketingType']=dataset.MarketingType.apply(lambda x: 0 if x=='D' else 1)dataset_0=dataset[dataset.SoldFlag=='0']dataset_1=dataset[dataset.SoldFlag=='1']dataset_train=pd.concat([dataset_0.iloc[:int(len(dataset_0)*0.8)],dataset_1.iloc[:int(len(dataset_1)*0.8)]])dataset_test=pd.concat([dataset_0.iloc[int(len(dataset_0)*0.8):],dataset_1.iloc[int(len(dataset_1)*0.8):]])train_y = dataset_train[[0]].values.ravel()train_x = dataset_train.iloc[:,1:].valuestest_x = dataset_test.iloc[:,1:].valuestest_y=dataset_test[[0]].values.ravel()# create and train the random forest# multi-core CPUs can use: rf = RandomForestClassifier(n_estimators=100, n_jobs=2)rf = RandomForestClassifier(n_estimators=100)rf.fit(train_x, train_y)pred = rf.predict(test_x)print rf.score(test_x,test_y)
阅读全文
0 0
- Historical Sales and Active Inventory kaggle
- Kaggle[4] - Online Product Sales
- historical stock and exchange data
- Kaggle之Grupo Bimbo Inventory Demand
- Marketing and Sales
- Sales and Distribution (SD)
- inventory
- Inventory
- Inventory
- inventory
- Dynamic historical stock data with d3.js and YQL
- 137.View the Exhibits and examine PRODUCTS and SALES tables.
- There are both historical and practical reasons why there is no ^^ operator.
- Kaggle
- KAGGLE
- kaggle
- Oracle Physical Inventory Adjustment Process and Data flow.
- Inventory Management system using AngularJS , PHP RESTful API and MySQL
- 面试题总结——JAV
- 【剑指offer】面试题7:两个栈实现队列
- 信息系统开发与管理--思维导图
- #include<filename.h> 和 #include"filename.h"有什么区别
- K:设计模式—绪论
- Historical Sales and Active Inventory kaggle
- POJ
- TCP为什么要三次握手?为什么要有四次挥手的TIME_WAIT?
- 1004 (BFS,DFS) vector
- Mybatis关于<foreach>中的index判断提示“Inappropriate OGNL expression”
- 关于Linux用户的一些介绍
- 模板方法模式(Template Method Pattern)——封装算法
- CMenu类中禁用-变灰某一项
- bzoj2809: [Apio2012]dispatching