-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfakeDataGenerator.py
More file actions
37 lines (34 loc) · 1.1 KB
/
fakeDataGenerator.py
File metadata and controls
37 lines (34 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@File : fakeDataGenerator.py
@Time : 2021/10/12
@Author : Yuanting Ma
@Version : 1.0
@Site : https://github.com/YuantingMaSC
@Contact : yuantingma@189.cn
"""
import pandas as pd
import numpy as np
import math
def generate(b0,b1,b2,b3,b4,num=25000):
x = pd.DataFrame()
x[0] = np.random.randint(0,1,num)+1 # 全1
x[1] = np.random.randint(low=12,high=60,size=num)
x[2] = np.random.random(size = (num,1))*60 + 40
x[3] = np.random.binomial(1,.45,num)
x[4] = np.random.binomial(1,.55,num)
x[5] = np.random.normal(0,1,num)
beta = np.matrix([b0,b1,b2,b3,b4]).T
X = np.matrix([x[0],x[1],x[2],x[3],x[4]]).T
x[6] = X @ beta + np.matrix(x[5]).reshape((num,1))
y = []
for i in range(num):
y.append(int(np.around(1/(1+np.exp(-x[6][i])))))
x[7]=y
res = x[[1,2,3,4,7]]
res.columns = ['x1', 'x2', 'x3', 'x4', 'y', ]
return res
data = generate(-.9,-0.2,0.05,0.5,0.3,500000)#5个系数(包括截距项)+生成的样本数量
print(data)
data.to_csv("fakedata_generated.csv",index=False)