Quick ML

Machine Learning & Data Science Practices

Image result for wolf of the wall street

Ever wondered, can we predict the stock prices ?  Investors make calculated guess by analyzing data like company history, news and industry trends they go into making a prediction.

But Stock Prices are completely random. Hence Finance companies like Morgan Stanely and citigroup hire data analyst to build the predictive models. In this age of algorithms today we'll check out this simple code which predicts the stock prices of Google so lets begin.

import quandl, math                                                                   
import numpy as np                                                                   
import pandas as pd                                                                   
from sklearn import preprocessing, cross_validation, svm       
from sklearn.linear_model import LinearRegression                

Here we first import all the required libraries such as math, numpy and pandas.
for those who do not know what is the use of this libraries here is just a quick overview of it

quandl  : Quandl is a marketplace for financial, economic and alternative data delivered in modern formats for today's analysts, including Python
pandas  : pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools
numpy  : used for scientific computing with python
sklearn : Machine Learning library used for data mining and analysis.
math     : It provides access to the mathematical functions defined by the C standard. ... Return fmod(x, y) , as defined by the platform C library.

If you dont know how to setup these libraries you can check it out here.

df = quandl.get("WIKI/GOOGL")
df = df[['Adj. Open',  'Adj. High',  'Adj. Low',  'Adj. Close', 'Adj. Volume']]
df['HL_PCT'] = (df['Adj. High'] - df['Adj. Low']) / df['Adj. Close'] * 100.0

df['PCT_change'] = (df['Adj. Close'] - df['Adj. Open']) / df['Adj. Open'] * 100.0

df = df[['Adj. Close', 'HL_PCT', 'PCT_change', 'Adj. Volume']]
forecast_col = 'Adj. Close'
df.fillna(value=-99999, inplace=True)
forecast_out = int(math.ceil(0.01 * len(df)))
df['label'] = df[forecast_col].shift(-forecast_out)

X = np.array(df.drop(['label'], 1))
X = preprocessing.scale(X)
X = X[:-forecast_out]
df.dropna(inplace=True)
y = np.array(df['label'])
X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, test_size=0.2)

clf = LinearRegression(n_jobs=-1)
clf.fit(X_train, y_train)
accuracy = clf.score(X_test, y_test)

print(accuracy)

I will stress that creating a linear model with say >95% accuracy is not that great. I certainly wouldn't trade stocks on it. There are still many issues to consider, especially with different companies that have different price trajectories over time. Google really is very linear: Up and to the right. Many companies aren't, so keep this in mind. Now, to forecast out, we need some data. We decided that we're forecasting out 1% of the data, thus we will want to, or at least *can* generate forecasts for each of the final 1% of the dataset. So when can we do this? When would we identify that data? We could call it now, but consider the data we're trying to forecast is not scaled like the training data was. Okay, so then what? Do we just do preprocessing.scale() against the last 1%? The scale method scales based on all of the known data that is fed into it. Ideally, you would scale both the training, testing, AND forecast/predicting data all together. Is this always possible or reasonable? No. If you can do it, you should, however. In our case, right now, we can do it. Our data is small enough and the processing time is low enough, so we'll preprocess and scale the data all at once.
In many cases, you wont be able to do this. Imagine if you were using gigabytes of data to train a classifier. It may take days to train your classifier, you wouldn't want to be doing this every...single...time you wanted to make a prediction. Thus, you may need to either NOT scale anything, or you may scale the data separately. As usual, you will want to test both options and see which is best in your specific case.

Final Words :

This is juts basic stock price predictor soon i'll be uploading an advance and more complex version of this and more amazing articles like this till then stay tuned.
You can get the code to this article from our github repository.
Share
Tweet
Pin
Share
No comments
Related image

To Get Started Doing things in Machine Learning and Data Science in the practical way we need to set up our computer to do certain things like computation and analysis. as I am using python on a Linux more specifically (ubuntu) platform we'll be setting up Python and required libraries to get things working. I will also mention the process for Windows OS so you can write and execute and perform ML and Data Science Practicals on your computer.

Image result for python 3
Downloading and Installing Python
For Linux Users
Linux comes with preinstalled python as well as python 3 so there is no need to download and install.
But you can always check the installed version and run the update command for it on your computer.
python --version   
sudo apt-get update python   
python3 --version   
sudo apt-get update python3   

sudo apt-get update    

For Windows Users

  • Windows Users can always the latest build of python from Download Python.
  • Then Run the setup.exe file that you just downloaded.
  • Be Sure you check "Add Path" checkbox to avoid any further error.
  • Once you are done Setting up Python Quickly run Terminal (for Linux) or Command Prompt (for Windows) 
  • Type " python3 "
  • If no error is prompted you are good to go further install pip package manager for Python3.
Image result for pip3 python 3.6
Installing pip package manager for Python
For Linux Users

  • Open Terminal
  • sudo apt-get install python3-pip
For Windows Users
Windows Users Can follow this very simple tutorial to enable pip in windows.



after you have successfully installed and enabled pip in your system then you can move to the next step and install python libraries.
Installing Python Libraries
  • From here steps are same for both system users.
  • Windows Users open command prompt and Linux users open their terminal to install these packages or libraries for your system type the given installation commands.
NumPy

Image result for NumPyNumPy is the fundamental package for scientific computing with Python. It contains among other things:
  • a powerful N-dimensional array object
  • sophisticated (broadcasting) functions
  • tools for integrating C/C++ and Fortran code
  • useful linear algebra, Fourier transform, and random number capabilities
Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases.

pip3 install numpy
SciPy
Image result for SciPyThe SciPy library is one of the core packages that make up the SciPy stack. It provides many user-friendly and efficient numerical routines such as routines for numerical integration and optimization.

pip3 install scipy
Pandas
Related imagepandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the Python programming language.

pip3 install pandas
Scikit Learn
Image result for sklearn
  • Simple and efficient tools for data mining and data analysis
  • Accessible to everybody, and reusable in various contexts
  • Built on NumPy, SciPy, and matplotlib

pip3 install scikit-learn
matplotlib
Related imageMatplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, the Python and IPython shells, the Jupyter notebook, web application servers, and four graphical user interface toolkits.

pip3 install matplotlib

Final Words
 As you have done setting up your machine you are good to go with Data Science and Machine learning practical approaches. Subscrbie to my newsletter and stay updated to our upcoming content.
Share
Tweet
Pin
Share
No comments

Related image
Data Science is the latest Buzz Word in the IT Industry Right Now. Every IT individual out there is trying to begin with Data Science and Machine Learning. In the world of Iron man & Jarvis some of also wish to build our own kick-ass AI program like Jarvis or Gideon to this Data Science and Machine Learning is the Key.

I am also a newb in Data Science  and Machine Learning as i started with Data Science and Machine Learning few days back so here is what i think you should do to start with Data Science and Machine Learning if you are thinking of getting into data science as a newbie. This is how i did or more specifically I am doing right now.

What does a Data Scientist do?
Data Science is an amalgamation of proper business understanding, mathematics, statistics, programming and communication skills. Thus one is expected to display all the above-mentioned skills in the role of a data scientist.
It is expected that a data scientist understands the business problem, builds a hypothesis, understands the kind of data required, performs data cleaning and preliminary data analysis, builds statistical models to give solution and finally effectively communicate the insights to the client. Thus, the job of a data scientist encompasses various roles and functions.
Image result for data scientist
How to Get Started with Data Science.
Teach Your Self to Code
No matter what type of company or role you’re interviewing for, you’re likely going to be expected to know how to use the tools of the trade. This means a statistical programming language, like R, Java or Python, and a database querying language like SQL.
Statistics is the Key
If you’re at a large company with huge amounts of data, or working at a company where the product itself is especially data-driven (e.g. Netflix, Google Maps, Uber), it may be the case that you’ll want to be familiar with machine learning methods. This can mean things like k-nearest neighbors, random forests, ensemble methods, and more. It’s true that a lot of these techniques can be implemented using R or Python libraries—because of this, it’s not necessarily to become an expert on how the algorithms work. More important is to understand the broad strokes and really understand when it is appropriate to use different techniques.
Do not forget Calculus & Linear Algebra
Understanding these concepts is most important at companies where the product is defined by the data, and small improvements in predictive performance or algorithm optimization can lead to huge wins for the company. In an interview for a data science role, you may be asked to derive some of the machine learning or statistics results you employ elsewhere. Or, your interviewer may ask you some basic multivariable calculus or linear algebra questions, since they form the basis of a lot of these techniques. You may wonder why a data scientist would need to understand this when there are so many out of the box implementations in Python or R. The answer is that at a certain point, it can become worth it for a data science team to build out their own implementations in house.
Image result for python libraries
Get Familiar with Programming Libraries
Python, R or Java libraries are the key aspects in Machine Learning as well as Data Science. Basic Knowledge of Python libraries like NumPy, Pandas and matplotlib would come in handy as a beginner. and you can always do a quick search on your own if you are looking for an extra.
Practice Practice Practice 
 You should keep practicing your newly learned skills and code with different data sets and solve mock problems available out there on the world wide web.

Final Words
Finally i would conclude this post as we have more in depth articles about getting started with python libraries and machine learning libraries and also some thoroughly explained Data Science and Machine Learning Projects as well as Challanges for you.
Do not forget to subscribe to my news letter.
Share
Tweet
Pin
Share
No comments

Read This in your Language

Pages

  • Home
  • Github - neural_works

Upcoming Projects

  • Titanic Survival Rate Prediction
  • Mobile Net Image Classifier
  • Categories

    • Machine Learning Projects
    • Data Visualization Projects
    • Data Science Projects

    About me

    This Blog is just about sharing my experiences as a Beginner and Newbie in Machine Learning and Data Science Journey.

    Facebook

    Powered by Blogger.

    Design By | Blog By Kshitij Bombarde