my net house


Tag Archives: python

Go and Python

Lots of stuff for GO and Python: Important to know and read as well.

Logging and importance of it with examples

Python and Flask supports wide range of logging as well. Either it’s warning, error or just a logger you can ago through all of those in very specific instance of time.

Logging is important of the Maintainability of the application.

Now logging is something like you need to go for when you see or feel that your web app needs lots of “Watching as well!”

Here is simple Example in Flask:

import logging
from logging.handlers import RotatingFileHandler

from flask import Flask

app = Flask(__name__)

def foo():
app.logger.warning('A warning occurred (%d apples)', 42)
app.logger.error('An error occurred')'Info')
return "foo"

if __name__ == '__main__':
handler = RotatingFileHandler('foo.log', maxBytes=10000, backupCount=1)

[/code ]

for more detailed view on logging and system you can go for the following link as well. :

It’s very much explanatory:

TPOT Python Example to Build Pipeline for AAPL

This is  just first Quick and Fast Post.

TPOT Research  Paper:

import datetime
import numpy as np
import pandas as pd
import sklearn
from pandas_datareader import data as read_data
from tpot import TPOTClassifier
from sklearn.model_selection import train_test_split

apple_data = read_data.get_data_yahoo("AAPL")
df = pd.DataFrame(index=apple_data.index)
df['multiple_day_returns'] =  df['price'].pct_change(3)
df['rolling_mean'] = df['daily_returns'].rolling(window = 4,center=False).mean()

df['time_lagged'] = df['price']-df['price'].shift(-2)

df['direction'] = np.sign(df['daily_returns'])
Y = df['direction']

X_train, X_test, y_train, y_test = train_test_split(X,Y,train_size=0.75, test_size=0.25)

tpot = TPOTClassifier(generations=50, population_size=50, verbosity=2), y_train)
print(tpot.score(X_test, y_test))

The Python file It returned: Which is real Code one can use to Create Trading Strategy. TPOT helped to Selected Algorithms and Value of It’s features. right now we have only provided ‘price’,’daily_returns’,’multiple_day_returns’,’rolling_mean’ to predict Target. One can use multiple features and implement as per the requirement.

import numpy as np
import pandas as pd
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.model_selection import train_test_split

# NOTE: Make sure that the class is labeled 'target' in the data file
tpot_data = pd.read_csv('PATH/TO/DATA/FILE', sep='COLUMN_SEPARATOR', dtype=np.float64)
features = tpot_data.drop('target', axis=1).values
training_features, testing_features, training_target, testing_target = \
            train_test_split(features, tpot_data['target'].values, random_state=42)

# Score on the training set was:1.0
exported_pipeline = GradientBoostingClassifier(learning_rate=0.5, max_depth=7, max_features=0.7500000000000001, min_samples_leaf=11, min_samples_split=12, n_estimators=100, subsample=0.7500000000000001), training_target)
results = exported_pipeline.predict(testing_features)

Learn Python and OOPS

Ok first of all when we think about OOPS we think about class.
yes Class
1.Create Class

class Honey:
#Object for class
#Access variable of class using object

#One more object
myandmy = Honey();
#assign new value to variable using object = “yackity”;
For using function just use object with function name. like meandme.functionname(). so I think we can also use other stuff too in Python class. That’s All

python sikhni hai

HOW to install SymPy on ubuntu —-> A full-featured computer algebra system (CAS)

SymPy is an open source Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python and does not require any external libraries.

The full features of sympy can be found here in the official page.. –

</p><p>Main page is at: <a href=”” rel=”nofollow“></a&gt; </p><p>

I want to share with you something more than first i will tell you how to install sympy a full featured package as follows

  • gmpy, Cython –> speed improvement
  • Pyglet, Matplotlib –> 2d and 3d plotting
  • IPython –> interactive sessions

gmpy,cython,pyglet,IPython can be used to extend this CAS functionality.Copy the following link in your browser  to download the script for the automation in installation of complete sympy package.just download the script and save it on your desktop and run the script.

How to run SAGE MATH on ubuntu 11.04

In my six week training i got the project related to sage math..Sage is a free open-source mathematics software system licensed under the GPL. It combines the power of many existing open-source packages into a common Python-based interface. my task was to complete study of sage and writing a python script for sage.

1.)first of all download the sage binary from the link

2.)choose your mirror for downloading..well i used the following mirror for fast downloading

3.)select your version 32 bit or 64 bit.

4.)after the completion of download you will get a file with the extensions of can be easily extracted in ubuntu linux using the command in terminal
“tar –lzma -xvf sage-*…tar.lzma” command
5.)if you are not so good with terminal then write click on the downloaded file and select extract here.

6.)when the file will be extracted completely open the terminal(alt+ctrl+t) and type following commands

cd /”path of the directory where sage file is located”/
cd /”name of the sage directory”/
if tou are able to run above commands successfully then in the terminal you will get the output like this. i downloaded file in the downloads directory and name of sage file is sage4.7

    then type “./sage” and you will able to run sage sucessfullly..if then any problem persist than first run command “sudo apt-get install gfortran” and then again again run start sage from terminal using “./sage”,, 🙂
%d bloggers like this: