Giter VIP home page Giter VIP logo

machine-learning-for-finance's Introduction

Machine Learning for Finance

This is the code repository for Machine Learning for Finance, published by Packt. It contains all the supporting project files necessary to work through the book from start to finish.

About the book

Machine Learning for Finance explores new advances in machine learning and shows how they can be applied in the financial sector. It explains the concepts and algorithms behind the main machine learning techniques and provides example Python code for implementing the models yourself.

How to run this code

The code in this repository is quite compute heavy and best run on a GPU enabled machine. The datascience platform Kaggle offers free GPU recourses together with free online Jupyter notebooks. To make edits on the Kaggle notebooks, click 'Fork' to create a new copy of the notebook. You will need a Kaggle account for this.

Alternatively you can just view the notebooks on NB Viewer or download the code and run it locally.

Chapter 1 - A neural Network from Scratch

A neural network from Scratch & Intro to Keras: Run on Kaggle, View Online

Excercise excel sheet: Download

Chapter 2 - Structured Data

Credit card fraud detection: Run On Kaggle, View Online

Chapter 3 - Computer Vision Building Blocks

Classifying MNIST digits: Run On Kaggle, View Online

Chapter 4 - Practical Computer Vision

Classifying Plants: View Online, Run On Colab

Intro to Python Generators: Run On Kaggle

Keras Generator with Logistic Regression: Run On Kaggle

Stacking VGG: Run On Kaggle

Preprocessing and Saving VGG Outputs: Run On Kaggle

Rule Based Preprocessing and Augmentation: Run On Kaggle

Visualizing ConvNets: Run On Kaggle

Chapter 5 - Time Series

Forecasting Web Traffic: Classic Methods: Run On Kaggle, View Online

Forecasting Web Traffic: Time Series Neural Nets: Run On Kaggle, View Online

Expressing Uncertainty with Bayesian Deep Learning: Run On Kaggle, View Online

Chapter 6 - Natural Language processing

Analyzing the News: Run On Kaggle, View Online

Classifying Tweets: Run On Kaggle, View Online

Topic modeling with LDA: Run On Kaggle, View Online

Sequence to Sequence models: Run On Kaggle, View Online

Chapter 7 - Generative Models

(Variational) Autoencoder for MNIST: Run On Kaggle, View Online

(Variational) Autoencoder for Fraud Detection: Run On Kaggle, View Online

MNIST DCGAN: Run On Kaggle, View Online

Semi Supervised Generative Adversarial Network for Fraud Detection: Run On Kaggle, View Online

Chapter 8 - Reinforcement Learning

Q-Learning: View Online

A2C Pole Balancing: View Online

A2C for Trading: Run On Kaggle View Online

Chapter 9 - Debugging ML Systems

Unit Testing Data: Run On Kaggle, View Online

Hyperparameter Optimization: View Online

Learning Rate Search: View Online

Using Tensorboard: View Online

Converting Keras Models to TF Estimators: View Online

Faster Python with Cython: Download Part 1, Download Part 2

Chapter 10 - Fighting Bias in Machine Learning

Understanding Parity in Excel: Download

Learning How to Pivot: View Online

Interpretability with SHAP: View Online

machine-learning-for-finance's People

Contributors

gauravgavas avatar jannesklaas avatar kishorrit avatar packt-itservice avatar packtutkarshr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

machine-learning-for-finance's Issues

ImportError: cannot import name 'SGD' from 'keras.optimizers'

Hi,

And even with the help of SOF I still cannot reproduce the numbers you've got in your git. I'm getting the following:

Epoch 1/5
13013/13013 [==============================] - 17s 1ms/step - loss: 825128.0000 - acc: 0.8998 - val_loss: 211068.5156 - val_acc: 0.9019
Epoch 2/5
13013/13013 [==============================] - 16s 1ms/step - loss: 766153.7500 - acc: 0.9068 - val_loss: 582742.2500 - val_acc: 0.8027


ImportError Traceback (most recent call last)
in ()
1 from keras.models import Sequential
2 from keras.layers import Dense, Activation
----> 3 from keras.optimizers import SGD

ImportError: cannot import name 'SGD' from 'keras.optimizers' (/usr/local/lib/python3.7/dist-packages/keras/optimizers.py)


NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.

NameError: name 'pred_func' is not defined

@JannesKlaas
Hi Jannes,
In chapater 1,
...
A deeper network
...

Helper function to plot a decision boundary.

If you don't fully understand this function don't worry, it just generates the contour plot below.

def plot_decision_boundary(pred_func):
# Set min and max values and give it some padding
x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
h = 0.01
# Generate a grid of points with distance h between them
xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
# Predict the function value for the whole gid
Z = pred_func(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
# Plot the contour and training examples
plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral)
plt.scatter(X[:, 0], X[:, 1], c=y.flatten(), cmap=plt.cm.Spectral)


NameError Traceback (most recent call last)
/tmp/ipykernel_27/694468409.py in
15
16 #Plot the decision boundary
---> 17 plot_decision_boundary(lambda x: predict(model, x))
18 plt.title("Decision Boundary for hidden layer size 3")
19

/tmp/ipykernel_27/2764471563.py in plot_decision_boundary(pre_func)
114 xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
115 #Predict the function value for the whole gid
--> 116 Z = pred_func(np.c_[xx_ravel(), yy_ravel()])
117 Z = Z.reshape(xx.shape)
118 #Plot the contour and training examples

NameError: name 'pred_func' is not defined

At page 54 , investigate zero balances as a feature of fraud detection

Hi,

At page 54 of this book, there is a formula for counting origin accounts have insufficient funds. As the code below:

     len(dfOdd[(dfOdd.oldBalanceOrig <= dfOdd.amount)]) / len(dfOdd)

This formula get 0.89664... , close to 90% of the odd transactions have insufficient funds.
Since we want accounts of insufficient funds before transaction. why use " <= " not. " < " ?
( The latter one get 0.21762... )

Regards,
Steven

Answers for the exercises

@JannesKlaas
Hi Jannes,

Thank you for the amazing book and the tutorials, I really appreciate the time and effort you have put into the book.

I am wondering if there is somewhere that you have posted the answers of the exercieses for us to double check?
Since this is completely self-study, having answers to look up would be helpful to let me know that I am at least in the right direction.

Thanks.

TypeError: only integer scalar arrays can be converted to a scalar index

I keep getting this error, trying to solve it but havent be able to, I am using python 3.0 from mini-conda, thanks.

epoch = 5000 # Number of games played in training, I found the model needs about 4,000 games till it plays well

# Train the model
# For simplicity of the noteb
hist = train(model, epoch, verbose=1)

print("Training done")

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-1e110d42c25b> in <module>
      3 # Train the model
      4 # For simplicity of the noteb
----> 5 hist = train(model, epoch, verbose=1)
      6 
      7 print("Training done")

<ipython-input-10-b5900a520e40> in train(model, epochs, verbose)
     12         game_over = False
     13         # get initial input
---> 14         input_t = env.observe()
     15 
     16         while not game_over:

<ipython-input-2-a9f37a9957fc> in observe(self)
     57 
     58     def observe(self):
---> 59         canvas = self._draw_state()
     60         return canvas.reshape((1, -1))
     61 

<ipython-input-2-a9f37a9957fc> in _draw_state(self)
     36         canvas[state[0], state[1]] = 1  # draw fruit
     37 
---> 38         canvas[-1, state[2] -1:state[2] + 2] = 1  # draw basket
     39 
     40         return canvas

TypeError: only integer scalar arrays can be converted to a scalar index

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.