In [1]:
%pylab inline
from classy import *
import numpy as np


Populating the interactive namespace from numpy and matplotlib
Keras not installed
Version:  0.0.24

In [2]:
data=load_excel('data/iris.xls',verbose=True)


iris.data 151 5
150 vectors of length 4
Feature names: 'petal length in cm', 'petal width in cm', 'sepal length in cm', 'sepal width in cm'
Target values given.
Target names: 'Iris-setosa', 'Iris-versicolor', 'Iris-virginica'
Mean:  [3.75866667 1.19866667 5.84333333 3.054     ]
Median:  [4.35 1.3  5.8  3.  ]
Stddev:  [1.75852918 0.76061262 0.82530129 0.43214658]

In [3]:
data_train=data

In [4]:
C=NaiveBayes()

In [5]:
timeit(reset=True)
C.fit(data_train.vectors,data_train.targets)
print("Training time: ",timeit())


Time Reset
Training time:  0.0016222000122070312 seconds 

In [6]:
mn=data.vectors.min(axis=0)
mx=data.vectors.max(axis=0)
mn,mx


Out[6]:
(array([1. , 0.1, 4.3, 2. ]), array([6.9, 2.5, 7.9, 4.4]))

In [7]:
np.mgrid?


Type:        MGridClass
String form: <numpy.lib.index_tricks.MGridClass object at 0x10c7cd250>
File:        ~/anaconda3/lib/python3.7/site-packages/numpy/lib/index_tricks.py
Docstring:  
`nd_grid` instance which returns a dense multi-dimensional "meshgrid".

An instance of `numpy.lib.index_tricks.nd_grid` which returns an dense
(or fleshed out) mesh-grid when indexed, so that each returned argument
has the same shape.  The dimensions and number of the output arrays are
equal to the number of indexing dimensions.  If the step length is not a
complex number, then the stop is not inclusive.

However, if the step length is a **complex number** (e.g. 5j), then
the integer part of its magnitude is interpreted as specifying the
number of points to create between the start and stop values, where
the stop value **is inclusive**.

Returns
----------
mesh-grid `ndarrays` all of the same dimensions

See Also
--------
numpy.lib.index_tricks.nd_grid : class of `ogrid` and `mgrid` objects
ogrid : like mgrid but returns open (not fleshed out) mesh grids
r_ : array concatenator

Examples
--------
>>> np.mgrid[0:5,0:5]
array([[[0, 0, 0, 0, 0],
        [1, 1, 1, 1, 1],
        [2, 2, 2, 2, 2],
        [3, 3, 3, 3, 3],
        [4, 4, 4, 4, 4]],
       [[0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4],
        [0, 1, 2, 3, 4]]])
>>> np.mgrid[-1:1:5j]
array([-1. , -0.5,  0. ,  0.5,  1. ])

In [16]:
step=0.2
w,x,y,z=np.mgrid[1:9:step,1:9:.5,1:9:step,1:9:step]

In [17]:
P = C.predict(np.c_[w.ravel(), x.ravel(), y.ravel(), z.ravel()])

In [18]:
len(P)


Out[18]:
1024000

In [19]:
import pandas as pd

In [20]:
w_data=list(data.vectors[:,0])
x_data=list(data.vectors[:,1])
y_data=list(data.vectors[:,2])
z_data=list(data.vectors[:,3])
c_data=list(data.targets)
L_data=[1]*len(c_data)

In [21]:
w_data.extend(w.ravel())
x_data.extend(x.ravel())
y_data.extend(y.ravel())
z_data.extend(z.ravel())
c_data.extend(P)
L_data=[0]*len(c_data)

In [22]:
fulldata=pd.DataFrame({
    data.feature_names[0]:w_data,
    data.feature_names[1]:x_data,
    data.feature_names[2]:y_data,
    data.feature_names[3]:z_data,
    'label':[data.target_names[i] for i in c_data],
    'label integer':c_data,
    'isdata':L_data,
})

In [23]:
fulldata.head()


Out[23]:
petal length in cm petal width in cm sepal length in cm sepal width in cm label label integer isdata
0 1.4 0.2 5.1 3.5 Iris-setosa 0 0
1 1.4 0.2 4.9 3.0 Iris-setosa 0 0
2 1.3 0.2 4.7 3.2 Iris-setosa 0 0
3 1.5 0.2 4.6 3.1 Iris-setosa 0 0
4 1.4 0.2 5.0 3.6 Iris-setosa 0 0

In [ ]:


In [26]:
fulldata.to_csv('bblais_test_classification1.csv',index=False)

In [25]:
fulldata.to_csv?


Signature:
fulldata.to_csv(
    path_or_buf=None,
    sep=',',
    na_rep='',
    float_format=None,
    columns=None,
    header=True,
    index=True,
    index_label=None,
    mode='w',
    encoding=None,
    compression='infer',
    quoting=None,
    quotechar='"',
    line_terminator=None,
    chunksize=None,
    date_format=None,
    doublequote=True,
    escapechar=None,
    decimal='.',
)
Docstring:
Write object to a comma-separated values (csv) file.

.. versionchanged:: 0.24.0
    The order of arguments for Series was changed.

Parameters
----------
path_or_buf : str or file handle, default None
    File path or object, if None is provided the result is returned as
    a string.  If a file object is passed it should be opened with
    `newline=''`, disabling universal newlines.

    .. versionchanged:: 0.24.0

       Was previously named "path" for Series.

sep : str, default ','
    String of length 1. Field delimiter for the output file.
na_rep : str, default ''
    Missing data representation.
float_format : str, default None
    Format string for floating point numbers.
columns : sequence, optional
    Columns to write.
header : bool or list of str, default True
    Write out the column names. If a list of strings is given it is
    assumed to be aliases for the column names.

    .. versionchanged:: 0.24.0

       Previously defaulted to False for Series.

index : bool, default True
    Write row names (index).
index_label : str or sequence, or False, default None
    Column label for index column(s) if desired. If None is given, and
    `header` and `index` are True, then the index names are used. A
    sequence should be given if the object uses MultiIndex. If
    False do not print fields for index names. Use index_label=False
    for easier importing in R.
mode : str
    Python write mode, default 'w'.
encoding : str, optional
    A string representing the encoding to use in the output file,
    defaults to 'utf-8'.
compression : str, default 'infer'
    Compression mode among the following possible values: {'infer',
    'gzip', 'bz2', 'zip', 'xz', None}. If 'infer' and `path_or_buf`
    is path-like, then detect compression from the following
    extensions: '.gz', '.bz2', '.zip' or '.xz'. (otherwise no
    compression).

    .. versionchanged:: 0.24.0

       'infer' option added and set to default.

quoting : optional constant from csv module
    Defaults to csv.QUOTE_MINIMAL. If you have set a `float_format`
    then floats are converted to strings and thus csv.QUOTE_NONNUMERIC
    will treat them as non-numeric.
quotechar : str, default '\"'
    String of length 1. Character used to quote fields.
line_terminator : str, optional
    The newline character or character sequence to use in the output
    file. Defaults to `os.linesep`, which depends on the OS in which
    this method is called ('\n' for linux, '\r\n' for Windows, i.e.).

    .. versionchanged:: 0.24.0
chunksize : int or None
    Rows to write at a time.
date_format : str, default None
    Format string for datetime objects.
doublequote : bool, default True
    Control quoting of `quotechar` inside a field.
escapechar : str, default None
    String of length 1. Character used to escape `sep` and `quotechar`
    when appropriate.
decimal : str, default '.'
    Character recognized as decimal separator. E.g. use ',' for
    European data.

Returns
-------
None or str
    If path_or_buf is None, returns the resulting csv format as a
    string. Otherwise returns None.

See Also
--------
read_csv : Load a CSV file into a DataFrame.
to_excel : Write DataFrame to an Excel file.

Examples
--------
>>> df = pd.DataFrame({'name': ['Raphael', 'Donatello'],
...                    'mask': ['red', 'purple'],
...                    'weapon': ['sai', 'bo staff']})
>>> df.to_csv(index=False)
'name,mask,weapon\nRaphael,red,sai\nDonatello,purple,bo staff\n'
File:      ~/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py
Type:      method

In [ ]: