AI Assisted Financial Platform Part02
AI Assisted Financial Platform Part02
APPENDIX 1
SYSTEM ENVIRONMENT
1.Curated Environments:
o Curated environments are preconfigured setups provided by platforms like Azure
Machine Learning. They come with a collection of essential Python packages
and settings optimized for various machine learning frameworks, allowing for
quick deployment and ease of use.
2.User-Managed Environments:
o In user-managed environments, you have full control over the setup. You are
responsible for installing all necessary packages and dependencies required for
your machine learning projects. This setup can be customized to fit specific
project needs and can include Bring Your Own Container (BYOC) options.
3.System-Managed Environments
o System-managed environments utilize tools like Conda to automatically manage
the Python environment. This approach simplifies dependency management by
creating a new Conda environment based on specified requirements, ensuring
that all necessary libraries are installed and configured correctly.
5.Cloud-Based Environments:
o Cloud-based environments, such as those provided by Azure or AWS, offer
scalable resources for machine learning tasks. These environments allow you to
leverage powerful compute instances and storage solutions while benefiting
from integrated tools for data management and model deployment.
2. Pipenv
➢ Pipenv is a dependency management tool that combines the functionalities
of pip and virtualenv. It automatically creates and manages a virtual environment for
your projects, as well as adds/removes packages from your Pipfile as needed. Pipenv
simplifies the process of managing dependencies and ensures that all package versions
are compatible with one another, making it easier to maintain project environments.
3. Jupyter Notebook
➢ Jupyter Notebook is an interactive computing environment that allows you to create
and share documents containing live code, equations, visualizations, and narrative text.
It supports various programming languages, including Python, and is widely used for
data analysis, visualization, and machine learning tasks. Jupyter Notebooks can be run
in a virtual environment to ensure that all required libraries are available for your
analysis without conflicts with other projects.
4.Interactive Notebooks:
VS Code supports Jupyter Notebooks, allowing data scientists to create and run
interactive documents that combine code execution with rich text elements like
equations and visualizations. This is particularly useful for exploratory data
analysis and model development.
6.Remote Development:
VS Code provides features for remote development, allowing users to connect
to remote servers or containers. This is beneficial for running heavy
computations or accessing large datasets without relying on local resources.
7.Environment Management:
The Python extension in VS Code facilitates easy selection and switching
between different Python interpreters and environments, streamlining the
workflow when working on multiple projects
8.Deployment Support:
VS Code can be integrated with deployment tools and services, enabling
smooth transitions from development to production environments. This
includes support for Docker containers and cloud deployments.
Applications:
• Text Generation: Producing coherent narratives or responses based on prompts.
• Question Answering: Providing accurate answers to user queries.
• Code Generation: Assisting developers in writing code snippets or solving
programming problems.
• Visual Reasoning: Understanding and interpreting images alongside text inputs.
Explanation of TypeScript, API-Based CRUD Operations, Clerk-Based
Authentication, and Neon-Based PostgreSQL:
TypeScript
TypeScript is a superset of JavaScript that introduces static typing to the
language. This feature helps developers catch errors at compile time rather than at
runtime, making it easier to maintain large codebases. TypeScript compiles down to
plain JavaScript, allowing it to run in any environment that supports JavaScript. It
supports advanced features such as interfaces, enums, and generics, which enhance code
organization and reusability. In the context of building APIs, TypeScript provides strong
typing for request and response objects, improving the reliability of data handling and
reducing runtime errors.
1. Creating an API: Set up an Express server and define routes for each CRUD
operation.
2. Connecting to a Database: Use an ORM like Mongoose (for MongoDB) or
Sequelize (for SQL databases) to manage data interactions.
3. Implementing Controllers: Write controller functions that handle incoming
requests, perform the necessary database operations, and send responses back
to the client.
4. Testing Endpoints: Use tools like Postman to test the API endpoints for
functionality and correctness.
Clerk-Based Authentication:
Clerk is an authentication service designed for modern web applications. It simplifies
user management by providing features such as user sign-up, sign-in, and session
management out of the box. Integrating Clerk into your application involves:
1. Setting Up Clerk: Create an account on Clerk's platform and configure your
application settings.
2. Integrating with Frontend: Use Clerk's SDK to add authentication
components directly into your frontend application.
3. Backend Integration: Protect your API routes by verifying user sessions using
Clerk's middleware in your Node.js application.
4. Managing Users: Utilize Clerk's dashboard to manage user accounts, roles,
and permissions effectively.
This setup enhances security by offloading authentication concerns to a dedicated
service while providing a seamless user experience.
Neon-Based PostgreSQL:
Neon is a serverless Postgres database designed for modern applications that require
scalability and flexibility. It offers features such as:
1. Serverless Architecture: Automatically scales resources based on demand,
allowing applications to handle varying workloads without manual
intervention.
2. Instant Snapshots: Provides point-in-time recovery options through instant
snapshots of your database state.
3. Seamless Integration: Works well with existing PostgreSQL clients and
libraries, making migration straightforward for developers familiar with
Postgres.
4. Cost Efficiency: Users only pay for the resources they consume, making it a
cost-effective solution for startups and growing applications.
Using Neon as your database solution allows developers to focus on building features
without worrying about infrastructure management.
Conclusion
Combining TypeScript with API-based CRUD operations, Clerk-based authentication,
and Neon-based PostgreSQL creates a robust framework for developing modern web
applications. This stack leverages the strengths of each component TypeScript's type
safety, Clerk's user management capabilities, and Neon's scalable database architecture
to deliver high-performance applications that are easy to maintain and secure.
APPENDIX 2
SOURCE CODE
import numpy as np
import pandas as pd
import warnings
warnings.filterwarnings("ignore")
pd.options.display.float_format='{:.4f}'.format
plt.rcParams['figure.figsize'] = [8,8]
pd.set_option('display.max_columns', 500)
pd.set_option('display.max_colwidth', -1)
sns.set(style='darkgrid')
%matplotlib inline
# import all the required libraries and dependencies for machine learning
import statsmodels.api as sm
import pickle
import gc
path = '../input/credit-card-fraud/creditcard.csv'
In [3]:
linkcode
df_card.head()
df_null = df_card.isnull().mean()*100
df_null.sort_values(ascending=False).head()
plt.figure(figsize=(13,7))
plt.subplot(121)
ax = df_card['Class'].value_counts().plot(kind='bar')
total = float(len(df_card))
for p in ax.patches:
height = p.get_height()
ax.text(p.get_x()+p.get_width()/2.,
height + 3,
'{:1.5f}'.format(height/total),
ha="center")
classes=df_card['Class'].value_counts()
normal_share=classes[0]/df_card['Class'].count()*100
fraud_share=classes[1]/df_card['Class'].count()*100
print(normal_share)
print(fraud_share)
#Scatter plot between Time and Amount
plt.scatter(df_nonfraud.Amount,
df_nonfraud.Time.values/(60*60),alpha=0.5,label='Non Fraud')
plt.scatter(df_fraud.Amount, df_fraud.Time.values/(60*60),alpha=1,label='Fraud')
plt.xlabel('Amount')
plt.ylabel('Time')
plt.show()
plt.legend(loc='upper right')
plt.show()
In [21]:
linkcode
pt = preprocessing.PowerTransformer(copy=False)
PWTR_X = pt.fit_transform(X)
kfold = 4
model_lr = LogisticRegression()
model_lr.fit(X_train, y_train)
y_predicted = model_lrh_tuned.predict(X_test)
In [39]:
linkcode
#Evaluation Metrices
model_rfc = RandomForestClassifier(n_jobs=-1,
random_state=2018,
criterion='gini',
n_estimators=100,
verbose=False)
In [42]:
model_rfc.fit(X_train,y_train)
y_predicted = model_rfc.predict(X_test)
In [43]:
linkcode
# Evaluation Metrics
SCREENSHOTS
[1]. Galton, F
"Regression towards mediocrity in hereditary stature."
Journal of the Anthropological Institute of Great Britain and Ireland, 1886, pp.
246–263.
[8]. Barros, R.C., Basgalupp, M.P., Carvalho, A.C.P.L.F., & Freitas, A.A.
"A Survey of Evolutionary Algorithms for Decision-Tree Induction."
IEEE Transactions on Systems, Man and Cybernetics: Applications and
Reviews*, 2012, 42(3), pp. 291-312.
[12]. Davis, J.V., Kulis, B., Jain, P., Sra, S., & Dhillon, I.S.
"Information-theoretic metric learning."
International Conference in Machine Learning (ICML); 2007; pp. 209-216.
[13]. Kulis, B.
"Metric learning: A survey."
Foundations and Trends in Machine Learning, 2013; 5(4):287-364.