반응형

/*******************************************************************************************************************
-- Title : [Py3.5] Using IRIS Dataset w/ Scikit-Learn
-- Reference : stackoverflow.com/questions/38105539
-- Key word : sklearn scikit-learn iris dataset dataframe 
*******************************************************************************************************************/

■ Scripts

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
38
39
40
41
42
43
44
45
46
47
48
49
import numpy as np
import pandas as pd
from sklearn.datasets import load_iris
 
 
# ------------------------------
# -- Set Dataframe Option
# ------------------------------
pd.set_option('display.height'1000)
pd.set_option('display.max_rows'500)
pd.set_option('display.max_columns'500)
pd.set_option('display.width'1000)
 
 
# ------------------------------
# -- iris dataset
# ------------------------------
# save load_iris() sklearn dataset to iris
# if you'd like to check dataset type use: type(load_iris())
# if you'd like to view list of attributes use: dir(load_iris())
iris = load_iris()
 
print(type(load_iris()))
print("... type""." * 100"\n")
 
print(dir(load_iris()))
print("... dir""." * 100"\n")
 
print(iris['feature_names'])
print("... feature_names""." * 100"\n")
 
print(iris['target'])
print("... target""." * 100"\n")
 
 
# ------------------------------
# -- change iris dataset to dataframe
# ------------------------------
 
# np.c_ is the numpy concatenate function
# which is used to concat iris['data'] and iris['target'] arrays 
# for pandas column argument: concat iris['feature_names'] list
# and string list (in this case one string); you can make this anything you'd like..  
# the original dataset would probably call this ['Species']
data1 = pd.DataFrame(data= np.c_[iris['data'], iris['target']],
                     columns= iris['feature_names'+ ['target'])
 
print (data1.head())
print(",,, dataframe from load_iris()""," * 100"\n")
cs



반응형

+ Recent posts