Python And Random Forest Algorithm
Question: I'm trying to use Python's Random Forest ML (machine learning) algorithm with
a *.csv file, and this is information is inside that *csv.file

    
    
    DateTime;Status;Energy
    28-02-2014 19:30:00;True;10,1
    28-02-2011 06:15:00;False;15,6;
    28-02-2011 06:30:00;False;15,2;
    28-02-2011 06:45:00;False;15,6;
    ......
    

Which packages or library(random forest models) do I need to use for analysis
with that information?

My code :

    
    
    from sklearn.ensemble import RandomForestClassifier
    from numpy import genfromtxt, savetxt
        def main():
            dataset = genfromtxt(open("C:\\Users\\PVanDro\\Desktop\\Ddata\\Building0.csv"), delimiter=';', dtype='f8')[1:]
            target = [x[0] for x in dataset]
            train = [x[1:] for x in dataset]
            rf = RandomForestClassifier(n_estimators=100)
            rf.fit(train, target)
            savetxt("C:\\Users\\PVanDro\\Desktop\\Ddata\\Building0_0.csv", delimiter=';', fmt='%f')
    
        if __name__=='__main__':
             main()
    

But i had errors :

    
    
      File "C:/Users/PVanDro/Desktop/Folder for test/RandomForestExamples1/MainFile.py", line 17, in main
        rf.fit(train, target)
      File "C:\Python27\lib\site-packages\sklearn\ensemble\forest.py", line 224, in fit
        X, = check_arrays(X, dtype=DTYPE, sparse_format="dense")
      File "C:\Python27\lib\site-packages\sklearn\utils\validation.py", line 283, in check_arrays
        _assert_all_finite(array)
      File "C:\Python27\lib\site-packages\sklearn\utils\validation.py", line 43, in _assert_all_finite
        " or a value too large for %r." % X.dtype)
    ValueError: Input contains NaN, infinity or a value too large for dtype('float32').
    

How i can fix that errors ?


Answer: This is a [great tutorial](https://www.kaggle.com/c/digit-
recognizer/forums/t/2299/getting-started-python-sample-code-random-forest)
that explains what you are looking for. Here is some sample code to try out.

    
    
    from sklearn.ensemble import RandomForestClassifier
    from numpy import genfromtxt, savetxt
    
    def main():
        #create the training & test sets, skipping the header row with [1:]
        dataset = genfromtxt(open('Data/train.csv','r'), delimiter=',', dtype='f8')[1:]    
        target = [x[0] for x in dataset]
        train = [x[1:] for x in dataset]
        test = genfromtxt(open('Data/test.csv','r'), delimiter=',', dtype='f8')[1:]
    
        #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, target)
    
        savetxt('Data/submission2.csv', rf.predict(test), delimiter=',', fmt='%f')
    
    if __name__=="__main__":
        main()
    

Once you have created your new, say predictive data set, you can use a
multitude of libraries to visualize that data with graphics. Here are a few:

  1. [Bokeh](http://bokeh.pydata.org/) \- A Python based visualization library for web-based representations
  2. [D3](http://d3js.org/) \- Another web-base JavaScript library for visualizing data. [Here](http://bl.ocks.org/mbostock/3887235) is one example you could use with CSV.
  3. [Ploty](https://plot.ly/python/) \- A Python based visualization

There are more, but You can interrogate Google for that. ;)

