Understand Python for Enterprise Artificial Intelligence
Learn AI by Working with a World-Class, No-Cost Advanced AI Computing Lab
Reinvent traditional software through DeepSphere.AI Enterprise AI platform through software engineering from hardcoded instruction-driven
automation to the machine self-learning application for the digital era.
Be Empowered by Our School of AI through Learning with Intelligent Automation
Learn Enterprise AI and Advanced Python without Coding
Acquire Cross-Functional Skills from Business to Data to Technology by Mastering AI
Learning Path

Learn How Our School of AI Teaches Workers to Transfer Business Processes to the Modern Digital World

Choose Your Hands-On Learning Unit
Develop an AI Application Using our Pre-Built Scala Libraries. Coding is No Longer Necessary
Master Artificial Intelligence with Hundreds of
Predeveloped Python Programs
- Unit 1Python Fundamentals
- Program #1Hellow World
- Program #2Variable
- Program #3Type Integer
- Program #4Type Floating Point
- Program #5Type String
- Program #6Complex Numbers
- Program #7Function Defining
- Program #8Dynamic Typing
- Program #9Static Typing
- Program #10Boolean Evaluation
- Program #11If Statement
- Program #12If Else Statement
- Program #13Else If Statement
- Program #14Block Structure
- Program #15Whitespaces
- Program #16Regular Expressions
- Program #17Lists
- Program #18Tuple
- Program #19Sets
- Program #20Frozen Sets
- Program #21Collection Transition
- Program #22Loop Else
- Program #23Arguments
- Program #24Mutable Arguments
- Program #25Accepting Variable Arguments
- Program #26Unpacking Argument List
- Program #27Scope
- Program #28Error Handling
- Program #29Namespaces
- Program #30File Input Output
- Program #31Higher Order Functions
- Program #32Anonymous Functions
- Program #33Nested Functions
- Program #34Closure
- Program #35Lexical Scoping
- Program #36Operator
- Program #37Decorators
- Program #38List Comprehensions
- Program #39Generator Expressions
- Program #40Generator Functions
- Program #41Itertools Chain
- Program #42Itertools Izip
- Program #43Debugging Tool Print
- Program #44Classes
- Program #45Emulation
- Program #46Class Method
- Program #47Static Method
- Program #48Inheritance
- Program #49Encapsulation
- Program #50N-Dimensional Array
- Unit 2Big Data Processing
- Program #51Reading Writing Data
- Program #52Reading Data From CSV
- Program #53Normalizing Data
- Program #54Formatting Data
- Program #55Controlling Line Properties Matplotlib
- Program #56Plotting Simple Function
- Program #57Importing Module
- Program #58Creating Module
- Program #59Graphing Matplotlib Using Defaults
- Program #60Graphing Matplotlib Using Defaults Changing Colors
- Program #61Graphing Matplotlib Using Defaults Setting Limits
- Program #62Graphing Matplotlib Using Defaults Setting Ticks
- Program #63Graphing Matplotlib Using Defaults Setting Tick Labels
- Program #64Graphing Matplotlib Using Defaults Moving Spines
- Program #65Graphing Matplotlib Using Defaults Adding Legends
- Program #66Graphing Matplotlib Using Defaults Annotating Points Legends
- Program #67Data Manipulation Using Pandas
- Program #68Reading Data From Hana To Python
- Unit 3Machine Learning: Part 1
- Program #69Reading Writing Data
- Program #70Reading Data From CSV
- Program #71Normalizing Data
- Program #72Formatting Data
- Program #73Controlling Line Properties Matplotlib
- Program #74Plotting Simple Function
- Program #75Importing Module
- Program #76Creating Module
- Program #77Graphing Matplotlib Using Defaults
- Program #78Graphing Matplotlib Using Defaults Changing Colors
- Program #79Graphing Matplotlib Using Defaults Setting Limits
- Unit 4Machine Learning: Part 2
- Program #80Isotonic Regression Scikit Learn
- Program #81Neural Networks Scikit Learn
- Program #82Non Linear Svm Scikit Learn
- Program #83Decision Trees Scikit Learn
- Program #84Plotting Validation Curve Scikit Learn
- Program #85Loading Datasets Scikit Learn
- Program #86Mean Shift Clustering Algorithm Scikit Learn
- Program #87Affinity Propagation Clustering Algorithm Scikit Learn
- Program #88Dbscan Clustering Algorithm Scikit Learn
- Program #89Kmeans Clustering Algorithm Scikit Learn
- Program #90Spectral Bi Clustering Algorithm Scikit Learn
- Program #91Spectral Co Clustering Algorithm Scikit Learn
- Program #92Ridge Regression Scikit Learn
- Unit 5Predictive Analytics
- Program #93Scientific Analysis Arrays Numpy
- Program #94Scientific Analysis Arrays Reshaping Numpy
- Program #95Scientific Analysis Arrays Concatenating Numpy
- Program #96Scientific Analysis Arrays Adding New Dimensions Numpy
- Program #97Scientific Analysis Arrays Initializing With Zeros Ones Numpy
- Program #98Scientific Analysis Mgrid Scipy
- Program #99Scientific Analysis Polynomial Scipy
- Program #100Scientific Analysis Vectorizing Functions Scipy
- Program #101Scientific Analysis Select Function Scipy
- Program #102Scientific Analysis General Integration Scipy
- Program #103Time Series Analysis Pandas
- Program #104Exporting Data Using Pandas
- Program #105Importing Data Using Pandas
- Program #106Data Analysis Pandas
- Unit 6Advanced Machine Learning
- Program #107Empty Graph Networkx
- Program #108Graph Adding Nodes Networkx
- Program #109Graph Adding Edges Networkx
- Program #110Graph Display Networkx
- Program #111Graph Path Networkx
- Program #112Renaming Nodes Networkx
- Program #113Example Pymc
- Program #114L1 Based Feature Selection
- Program #115Line Plot Matplotlib
- Program #116Dot Plot Matplotlib
- Program #117Numeric Plot Matplotlib
- Program #118Figures Axes Matplotlib
- Program #1192D Plotting Mapplotlib
- Program #1202D Plot Scikit Learn
- Program #121Classification Scikit Learn
- Program #122Model Selection Scikit Learn
- Program #123Nearest Neighbours Regression Scikit Learn
- Unit 7Data Visualization
- Program #124Graphing Matplotlib Regular Plot
- Program #125Graphing Matplotlib Scatter Plot
- Program #126Graphing Matplotlib Bar Plot
- Program #127Graphing Matplotlib Contour Plot
- Program #128Graphing Matplotlib Imshow
- Program #129Graphing Matplotlib Pie Chart
- Program #130Graphing Matplotlib Quiver Plot
- Program #131Graphing Matplotlib Grids
- Program #132Graphing Matplotlib Multi Plots
- Program #133Graphing Matplotlib Polar Axis
- Program #134Graphing Matplotlib 3D Plot
- Program #135Graphing Matplotlib Texts
- Program #136Histogram Matplotlib
- Unit 8Use Case Implementation: Part 1
- Program #137Bed Occupancy Optimization
- Program #138Life Time Value Customer Prediction
- Program #139Customer Upselling Characteristics Prediction
- Program #140Sales Lead Priortization
- Program #141Inventory Demand Forecasting
- Program #142Credit Card Fraud Risk
- Program #143Employee Churn Prediction
- Program #144Patient Medication Complaince Prediction
- Program #145Physician Attrition Prediction
- Program #146Patient Readmittance Rate Prediction
- Program #147Patient Insurance Claim Prediction
- Program #148Drug Demand Forecasting
- Unit 9Use Case Implementation: Part 2
- Program #149Customer Retention Analysis
- Program #150Hospital Bed Turn Analysis
- Program #151Patient Survival Analysis
- Program #152Patient Medication Effectiveness Analysis
- Program #153Sales Growth Analysis
- Program #154Customer Cross Selling Analysis
- Program #155Product Customer Segmentation
- Program #156Employee Talent Mangement
- Program #157Patient Bed Occupancy
- Program #158Product Market Basket Analysis
- Program #159Automobile Claims Handling Analysis
- Program #160Customer Market Share
- Unit 10Advanced Data Processing
- Program #161Data Collection From Excel
- Program #162Data Collection From CSV
- Program #163Data Collection From Clipboard
- Program #164Data Collection From HTML
- Program #165Data Collection From XML
- Program #166Data Collection From JSON
- Program #167Data Collection From PDF
- Program #168Data Collection From Plain Text
- Program #169Data Collection From DOCX
- Program #170Data Collection From HDF
- Program #171Data Collection From Image
- Program #172Data Collection From MP3
- Program #173Data Collection From SAP HANA
- Program #174Data Collection From Hadoop
- Program #175Data Integration Concatenate
- Program #176Data Integration Merge
- Program #177Data Integration Join
- Program #178Data Mapping Dictionary Literal Values
- Program #179Data Mapping Dictionary Operations
- Program #180Data Mapping Dictionary Comparision Operations
- Program #181Data Mapping Dictionary Statments
- Program #182Data Provisioning Extraction
- Program #183Data Provisioning Transformation
- Program #184Data Provisioning Loading
- Unit 11Advanced Programming
- Program #185Iterators
- Program #186Generator Expressions
- Program #187Generators
- Program #188Bidirectional Communication
- Program #189Chaining Generators
- Program #190Decorators
- Program #191Decorators As Functions
- Program #192Decorators As Classes
- Program #193Decorators Copying Docstring Other Attributes
- Program #194Example Standard Library
- Program #195Depriciation Of Functions
- Program #196While Loop Removing Decorator
- Program #197Plugin Registration System
- Program #198Context Managers
- Program #199Context Managers Catching Exceptions
- Program #200Context Managers Defining Using Generators
- Program #201Ndarray
- Program #202Ndarray Block Of Memory
- Program #203Ndarray Data Type
- Program #204Ndarray Indexing Scheme Strides
- Program #205Ndarray Slicing With Integers
- Program #206Ndarray Transposing With Integers
- Program #207Ndarray Reshaping Integers
- Program #208Ndarray Broadcasting
- Program #209Ndarray Universal Function
- Program #210Ndarray Generalized Universal Function
- Program #211Ndarray Old Buffer Protocol
- Program #212Processing Opening Writing To Image
- Program #213Image Processing Displaying Images
- Program #214Image Processing Displaying Images Basic Manipulation
- Program #215Image Processing Geometrical Transformations
- Program #216Image Processing Filtering Blurring
- Program #217Image Processing Filtering Sharpening
- Program #218Image Processing Filtering Denoising
- Program #219Image Processing Filtering Apply Gaussian Filter
- Program #220Image Processing Filtering Apply Median Filter
- Program #221Image Processing Feature Extraction Edge Detection
- Program #222Image Processing Feature Extraction Segmentation
- Unit 12Working with Tensorflow
- Program #223Tensorflow Hello World
- Program #224Tensorflow Tensors
- Program #225Tensorflow Fixed Tensors
- Program #226Tensorflow Sequence Tensors
- Program #227Tensorflow Randon Tensors
- Program #228Tensorflow Constants
- Program #229Tensorflow Variables
- Program #230Tensorflow Placeholders
- Program #231Tensorflow Graphs
- Program #232Tensorflow Session
- Program #233Tensorflow Feed Dictionary
- Program #234Tensorflow Data Type
- Program #235Tensorflow Add Two Consatnts
- Program #236Tensorflow Multiply Two Consatnts
- Program #237Tensorflow Matrix Inverse Method
- Program #238Tensorflow Queues
- Program #239Tensorflow Saving Variables
- Program #240Tensorflow Restoring Variables
- Program #241Tensorflow Tensorboard
- Program #242Tensorflow Namescope
- Program #243Tensorflow Linear Regression
- Program #244Tensorflow Logistic Regression
- Program #245Tensorflow Random Forest
- Program #246Tensorflow Kmeans Clustering
- Program #247Tensorflow Linear Support Vector Machine
- Program #248Tensorflow Non Linear Support Vector Machine
- Program #249Tensorflow Multi Class Support Vector Machine
- Program #250Tensorflow Nearest Neighbours
- Program #251Tensorflow Neural Networks
- Program #252Tensorflow Convolutional Neural Networks
- Program #253Tensorflow Deep Neural Networks
- Unit 13Working with NLP
- Program #254NLP Installing Nltk
- Program #255NLP Count Word Frequency Nltk
- Program #256NLP Remove Stop Words
- Program #257NLP Tokenize Text Nltk
- Program #258NLP Tokenize Non English Text Nltk
- Program #259NLP Get Synonyms Nltk
- Program #260NLP Get Antonyms Nltk
- Program #261NLP Word Stemming Nltk
- Program #262NLP Non English Word Stemming Nltk
- Program #263NLP Lemmatizing Words Nltk
- Program #264NLP Part Of Speech Tagging Nltk
- Program #265NLP Chinking Nltk
- Program #266NLP Chunking Nltk
- Program #267NLP Corpora Nltk
- Program #268NLP Named Entity Recognition Nltk
- Program #269NLP Text Classification Nltk
- Program #270NLP Converting Words To Features Nltk
- Program #271NLP Naive Bayes Classifier Nltk
- Program #272NLP Save Classifier Nltk
- Program #273NLP Scikit Learn Algorithms Nltk
- Program #274NLP Combining Algorithms Nltk
- Program #275NLP Noise Removal Nltk
- Program #276NLP Noise Removal Regular Expressions Nltk
- Program #277NLP Object Standardization Nltk
- Program #278NLP Topic Modelling Nltk
- Program #279NLP Ngrams Nltk
- Program #280NLP Tfidf Vectorizer_nltk
- Program #281NLP Word Embedding Nltk
- Program #282NLP Text Matching Levenshtein Distance Nltk
- Program #283NLP Cosine Similarity Nltk
- Program #284NLP Wordnet Nltk
- Unit 14Working with Computer Vision
- Program #285Computer Vision Install Opencv
- Program #286Computer Vision Reading Images Opencv
- Program #287Computer Vision Displaying Images Opencv
- Program #288Computer Vision Writing Images Opencv
- Program #289Computer Vision Color Space Opencv
- Program #290Computer Vision Thresholding Opencv
- Program #291Computer Vision Finding Contours Opencv
- Program #292Computer Vision Image Scaling Opencv
- Program #293Computer Vision Image Rotation Opencv
- Program #294Computer Vision Image Translation Opencv
- Program #295Computer Vision Image Edge Detection Opencv
- Program #296Computer Vision Image Filtering Opencv
- Program #297Computer Vision Image Filtering Blurring Opencv
- Program #298Computer Vision Image Filtering Blurring Gaussian Blur Opencv
- Program #299Computer Vision Image Filtering Blurring Median Blur Opencv
- Program #300Computer Vision Image Filtering Bilateral Opencv
- Program #301Computer Vision Morphological Operations Erosion Opencv
- Program #302Computer Vision Morphological Operations Dilation Opencv
- Program #303Computer Vision Morphological Operations Opening Opencv
- Program #304Computer Vision Morphological Operations Closing Opencv
- Program #305Computer Vision Morphological Operations Gradient Opencv
- Program #306Computer Vision Morphological Operations Tophat Opencv
- Program #307Computer Vision Morphological Operations Blackhat Opencv
- Program #308Computer Vision Image Gradients Sobel Opencv
- Program #309Computer Vision Image Gradients Scharr Opencv
- Program #310Computer Vision Image Gradients Laplacian Opencv
- Program #311Computer Vision Canny Edge Detection Opencv
- Program #312Computer Vision Gaussian Pyramid Opencv
- Program #313Computer Vision Contours Opencv
- Program #314Computer Vision Histograms Opencv
- Program #315Computer Vision Histograms With Mask Opencv
- Program #316Computer Vision Fourier Transform Opencv
- Program #317Computer Vision Template Matching Opencv
- Unit 15Working with RPA
- Program #318RPA Install Automagica
- Program #319RPA Open Notepad Type Hello World Automagica
- Program #320RPA Open Chrome Browser Automagica
- Program #321RPA Automate Mouse Movements Automagica
- Program #322RPA Function To Open Dropbox Automagica
- Program #323RPA List Running Processes Automagica
- Program #324RPA Return Elements Automagica
- Program #325RPA Extract Text From Pdf Automagica
- Program #326RPA Merge Pdf Automagica
- Program #327RPA File Manipulation Ename File Automagica
- Program #328RPA File Manipulation Moving File Automagica
- Program #329RPA File Manipulation Copying File Automagica
- Program #330RPA Image Operation Open Image Automagica
- Program #331RPA Image Operation Rotating Image Automagica
- Program #332RPA Image Operation Resizing Image Automagica
- Program #333RPA Strings Automagica
- Program #334RPA String Manipulation Automagica
- Unit 16Working with Deep Learning
- Program #335Deep Learning Introduction
- Program #336Deep Learning Loading Our Own Training Data
- Program #337Deep Learning Convolutional Neural Networks
- Program #338Deep Learning Analyzing Models With Tensorboard
- Program #339Deep Learning Optimizing Models With Tensorboard
- Program #340Deep Learning Use Trained Model
- Program #341Deep Learning Recurrent Neural Networks
- Program #342Deep Learning Normalizing Creating Sequences
- Program #343Deep Learning Keras Mnist Classification
- Program #344Deep Learning Linear Regression
- Program #345Deep Learning Logistic Regression
- Program #346Deep Learning Random Forest
- Program #347Deep Learning Kmeans Clustering
- Program #348Deep Learning Linear Support Vector Machine
- Program #349Deep Learning Non Linear Support Vector Machine
- Program #350Deep Learning Multi Class Support Vector Machine
- Program #351Deep Learning Nearest Neighbours
- Program #352Deep Learning Neural Networks
- Program #353Deep Learning Keras Imdb Classification
- Program #354Deep Learning Keras Cifar10 Cnn Classification
- Program #355Deep Learning Keras Mnist Mlp Classification
- Program #356Deep Learning Intercompany Transaction Classification
- Program #357Deep Learning Pair Intercompany Transaction Autoencoder Kmeans
- Program #358Deep Learning Pair Intercompany Transaction For Difference In Booking Ae Kmeans
- Program #359Deep Learning Predict Weighted Accuracy Of Intercompany Transaction Ann
- Program #360Deep Learning Predict Weighted Accuracy Of Intercompany Transaction Rnn
- Program #361Deep Learning Partitioned Embeddings
- Program #362Deep Learning Shape Embeddings
- Program #363Deep Learning Gradient Numgrad Function
Purpose : A Simple Hello World Program in Python
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 11:00 hrs
Version : 1.0
## Program Description : A "Hello, World!" Program in Python ## Python Development Environment & Runtime - Python, Anaconda print ("Hello World!") /************** Disclaimer: We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product. /**************
Purpose : A Program to show Variables in Python
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 11:00 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Variables for Integer, Floating Point Integer & String Assignment in Python
## Python Development Environment & Runtime - Python, Anaconda
# An Integer Assignment
vAR_Counter = 100
# Floating Point Integer Assignment
vAR_Miles = 1000.0
# String Assignment
vAR_Name = "John"
print (vAR_Counter)
print (vAR_Miles)
print (vAR_Name)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_TYPE_INTEGER_V1
Purpose : A Program in Python to show Integer Assignment
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 11:58 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Integer Assignment by Variables in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_Counter = 100
print (vAR_Counter)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_TYPE_FLOATING_POINT_V1
Purpose : A Program in Python to show Floating Point Integer Assignment
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 12:57 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Floating Point Integer Assignment by Using Variables in Python
## Python Development Environment & Runtime - Python, Anaconda
# A floating Point Integer Assignment vAR_Miles = 1000.0
print (vAR_Miles)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_TYPE_STRING_V1
Purpose : A Program in Python to show String Assignment
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 13:12 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Usage of Strings in Python
## Python Development Environment & Runtime - Python, Anaconda
# String Assignment
vAR_Name = "John"
print (vAR_Name)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_COMPLEX_NUMBERS_V1
Purpose : A Program in Python to show Complex Numbers
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 14:04 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Complex Numbers in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_Z = 2+3j
vAR_Z.real
vAR_Z.imag
vAR_Z.conjugate()
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_DEFINE_FUNCTIONS_V1
Purpose : A Program in Python to Define Functions
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 14:32 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Defining Functions in Python
## Python Development Environment & Runtime - Python, Anaconda
def vAR_My_Function():
print("Hello from a function")
vAR_My_Function()
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_DYNAMIC_TYPING
Purpose : A Program in Python for Dynamic Typing
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 15:03 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Dynamic Typing in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_EMPNAME = 9
vAR_EMPNAME = "Steve Ferg"
print(vAR_EMPNAME)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_STATIC_TYPING
Purpose : A Program in Python for Static Typing
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 15:37 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Static Typing in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_A = 9
vAR_B = "9"
print(vAR_A)
print(vAR_B)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_BOOLEAN_EVALUATION
Purpose : A Program in Python for Boolean Evaluation
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 15:37 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Boolean Evaluation in Python
## Python Development Environment & Runtime - Python, Anaconda
5 == 5
5 == 6
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_IF_STATEMENT
Purpose : A Program in Python for If Statement
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 16:18 hrs
Version : 1.0
/****************************************
## Program Description : A Program for IF Statement in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR1 = 100
if vAR1:
print ("Got a true expression value")
print(vAR1)
vAR2 = 0
if vAR2:
print ("Got a true expression value")
print(vAR2)
print ("Good bye!")
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_IF_ELSE_STATEMENT
Purpose : A Program in Python for Ifelse Statement
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 16:49 hrs
Version : 1.0
/****************************************
## Program Description : A Program for IF Else Statement in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR1 = 100
if vAR1:
print ("1 - Got a true expression value")
print (vAR1)
else:
print ("1 - Got a false expression value")
print (vAR1)
vAR2 = 0
if vAR2:
print ("2 - Got a true expression value")
print (vAR2)
else:
print ("2 - Got a false expression value")
print (vAR2)
print ("Good bye!")
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/************
/****************************************
File Name : CSLAB_ELSE_IF_STATEMENT
Purpose : A Program in Python for Else If Statement
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 16:49 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Else if Statement in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR = 100
if vAR == 200:
print ("1 - Got a true expression value")
print (vAR)
elif vAR == 150:
print ("2 - Got a true expression value")
print(vAR)
elif vAR == 100:
print ("3 - Got a true expression value")
print(vAR)
else:
print ("4 - Got a false expression value")
print (vAR)
print ("Good bye!")
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/************
/****************************************
File Name : CSLAB_BLOCK_STRUCTURE
Purpose : A Program in Python for Block Structure
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 9:28 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Block Structure in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_i = 25
if vAR_i < 0:
print ("vAR_i is negative")
else:
print ("vAR_i is Non Negative")
if vAR_i < 10:
print ("vAR_i has one digit")
else:
print ("vAR_i has multiple digits")
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/************
/****************************************
File Name : CSLAB_WHITESPACES
Purpose : A Program in Python for Whitespaces
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 9:57 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Whitespaces in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_X = 49
for vAR_X in range(0, 5):
print (vAR_X)
print (2*vAR_X)
print (vAR_X)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/************
/****************************************
File Name : CSLAB_REGULAR_EXPRESSIONS
Purpose : A Program in Python for Regular Expressions
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 10:29 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Regular Expressions in Python
## Python Development Environment & Runtime - Python, Anaconda
import re
pattern = re.compile(r"[(on|off)]") # Slight optimization
print(re.search(pattern, "Mono: Playback 65 [75%] [-16.50dB] [on]"))
# Returns a Match object!
print(re.search(pattern, "Nada...:-("))
# Doesn't return anything.
# End Example
# Exercise: make a regular expression that will match an email
def test_email(your_pattern):
pattern = re.compile(your_pattern)
emails = ["john@example.com", "python-list@python.org", "wha.t.`1an?ug{}ly@email.com"]
for email in emails:
if not re.match(pattern, email):
print("You failed to match %s" % (email))
elif not your_pattern:
print("Forgot to enter a pattern!")
else:
print("Pass")
pattern = r"" # Your pattern here!
test_email(pattern)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/************
/****************************************
File Name : CSLAB_LISTS
Purpose : A Program in Python for Lists
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 11:08 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Lists in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_LIST1 = ['Physics', 'Chemistry', 1997, 2000]; vAR_LIST2 = [1, 2, 3, 4, 5 ]; vAR_LIST3 = ["a", "b", "c", "d"];
print (vAR_LIST1)
print (vAR_LIST2)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_TUPLE
Purpose : A Program in Python for Tuple
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 11:47 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Creation of Tuple in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_Tuple = ("Apple", "Banana", "Cherry")
for x in vAR_Tuple: print(x)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_SETS_V1
Purpose : A Program in Python for Sets
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 12:13 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Creation of Sets in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_A = {1, 2, 3}
vAR_A = set('qwerty')
print(vAR_A)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_FROZEN_SETS_V1
Purpose : A Program in Python for Frozen Sets
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 12:54 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Creation of Frozen Sets in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_CITIES = set(["Frankfurt", "Basel","Freiburg"])
vAR_CITIES.add("Strasbourg")
vAR_CITIES
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_COLLECTION_TRANSITION_V1
Purpose : A Program in Python for Collection Trasition
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 13:22 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Creation of Collection Transition in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_characters = {'hero': 'Othello', 'villain': 'Iago', 'friend': 'Cassio'}
vAR_roles = CSLAB_characters.keys()
vAR_roles
vAR_names = CSLAB_characters.values()
print(vAR_roles)
print(vAR_names)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_LOOP_ELSE_V1
Purpose : A Program in Python for LOOP-ELSE
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 13:51 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Else Statement in Loops in Python
## Python Development Environment & Runtime - Python, Anaconda
for vAR_n in range(2, 10):
for vAR_x in range(2, vAR_n):
if vAR_n % vAR_x == 0:
print(vAR_n, 'equals', x, '*', vAR_n/vAR_x)
break
else:
# loop fell through without finding a factor
print(vAR_n, 'is a prime number')
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_ARGUMNETS_V1
Purpose : A Program in Python for Arguments
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 9:38 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Usage of Arguments in Python
## Python Development Environment & Runtime - Python, Anaconda
import sys
print ('Number of arguments:', len(sys.argv), 'arguments.')
print ('Argument List:', str(sys.argv))
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_MUTABLE_ARGUMNETS_V1
Purpose : A Program in Python for Mutable Arguments
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 10:07 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Usage of Mutable Arguments in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_MY_LIST = ["apple", "pear"]
print("My_list:", vAR_MY_LIST)
print("ID of x before modification:", id(vAR_MY_LIST))
# append "banana" to my_list
vAR_MY_LIST.append("banana")
print("my_list:", vAR_MY_LIST)
print("ID of x after modification:", id(vAR_MY_LIST))
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_ACCEPTING_VARIABLE_ARGUMENTS_V1
Purpose : A Program in Python for Accepting Variable Arguments
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 10:41 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Accepting Variable Arguments in Python
## Python Development Environment & Runtime - Python, Anaconda
def vAR_myFun(vAR_arg1, vAR_arg2, vAR_arg3):
print("arg1:", vAR_arg1)
print("arg2:", vAR_arg2)
print("arg3:", vAR_arg3)
# Now we can use *args or **kwargs to
# pass arguments to this function :
vAR_args = ("Geeks", "for", "Geeks")
myFun(*vAR_args)
vAR_kwargs = {"vAR_arg1" : "Geeks", "vAR_arg2" : "for", "vAR_arg3" : "Geeks"} vAR_myFun(**vAR_kwargs)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_UNPACKING_ARGUMENT_LIST_V1
Purpose : A Program in Python for Unpacking Argument List
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 11:41 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Accepting Unpacking Arguments in Python
## Python Development Environment & Runtime - Python, Anaconda
# A sample function that takes 4 arguments
# and prints the,
def fun(a, b, c, d):
print(a, b, c, d)
# Driver Code
my_list = [1, 2, 3, 4]
# Unpacking list into four arguments
fun(*my_list)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_SCOPE_V1
Purpose : A Program in Python for Scope
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 12:13 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Usage of Scope in Python
## Python Development Environment & Runtime - Python, Anaconda
def deep_scope():
if True:
if True:
if True:
CSLAB_X = 5
return CSLAB_X
deep_scope()
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_ERROR_HANDLING_V1
Purpose : A Program in Python for Error Handling
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 13:00 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Error Handling in Python
## Python Development Environment & Runtime - Python, Anaconda
Total_Marks = int(input("Enter Total Marks Scored: "))
Num_of_Sections = int(input("Enter Num of Sections: "))
Average = 0
try:
Average = int(Total_Marks/Num_of_Sections)
except ZeroDivisionError:
print("Error:There has to be atleast 1 or more than 1 sections.")
print("Average marks scored per section is: ",Average)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_NAMESPACES_V1
Purpose : A Program in Python for Namespaces
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 13:44 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Usage of Namespaces in Python
## Python Development Environment & Runtime - Python, Anaconda
def outer_function():
vAR_a = 20
def inner_function():
vAR_a = 30
print('a =',vAR_a)
inner_function()
print('a =',vAR_a)
vAR_a = 10
outer_function()
print('a =',vAR_a)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_FILE_INPUT_OUTPUT_V1
Purpose : A Program in Python for File Input/Output Functions
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 16:27 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Usage of Input/Output Functions in Python
## Python Development Environment & Runtime - Python, Anaconda
colors = ['redn', 'yellown', 'bluen']
f = open('colors.txt', 'w')
f.writelines(colors)
f.close()
f = open('colors.txt')
f.readline()
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_HIGHER_ORDER_FUNCTIONS_V1
Purpose : A Program in Python for Higher order Functions
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 09:34 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Higher Order Functions in Python
## Python Development Environment & Runtime - Python, Anaconda
def second_element(t): return t[1]
zepp = [('Guitar', 'Jimmy'), ('Vocals', 'Robert'), ('Bass', 'John Paul'), ('Drums', 'John')]
sorted(zepp)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_ANONYMOUS_FUNCTIONS_V1
Purpose : A Program in Python for Anonymous Functions
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 10:03 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Anonymous Functions in Python
## Python Development Environment & Runtime - Python, Anaconda
def call_func(f, *args): return f(*args)
call_func(lambda x, y: x + y, 4, 5)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_NESTED_FUNCTIONS_V1
Purpose : A Program in Python for Nested Functions
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 10:37 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Nested Functions in Python
## Python Development Environment & Runtime - Python, Anaconda
def outer():
def inner(a): return a
return inner
f = outer()
f
f(10)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_CLOSURE_V1
Purpose : A Program in Python for Closures
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 11:12 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Closures in Python
## Python Development Environment & Runtime - Python, Anaconda
def outer2(a):
def inner2(b):
return a + b
return inner2
add1 = outer2(1)
add1
add1(4)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/*******
File Name : CSLAB_LEXICAL_SCOPING_V1
Purpose : A Program in Python for Lexical Scoping
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 11:47 hrs
Version : 1.0
/**************
## Program Description : A Program for Lexical Scoping in Python
## Python Development Environment & Runtime - Python, Anaconda
def vAR_CSLAB_increment(vAR_CSLAB_n):
vAR_CSLAB_n += 1
print(vAR_CSLAB_n)
return vAR_CSLAB_n
vAR_CSLAB_n = 1
vAR_CSLAB_increment(vAR_CSLAB_n)
print(vAR_CSLAB_n)
/*******
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******
/****************************************
File Name : CSLAB_OPERATOR_V1
Purpose : A Program in Python for Operators
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 12:18 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Operators in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_x = 15
vAR_y = 4
## Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication etc
# Output: x + y = 19
print('vAR_x + vAR_y =',vAR_x+vAR_y)
# Output: x - y = 11
print('vAR_x - vAR_y =',vAR_x-vAR_y)
# Output: x * y = 60
print('vAR_x * vAR_y =',vAR_x*vAR_y)
# Output: x / y = 3.75
print('vAR_x / vAR_y =',vAR_x/vAR_y)
# Output: x // y = 3
print('vAR_x // vAR_y =',vAR_x//vAR_y)
# Output: x ** y = 50625
print('vAR_x ** vAR_y =',vAR_x**vAR_y)
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
## Comparison operators are used to compare values. It either returns True or False according to the condition.
vAR_x = 10
vAR_y = 12
# Output: x > y is False
print('vAR_x > vAR_y is',vAR_x>vAR_y)
# Output: x < y is True
print('vAR_x < vAR_y is',vAR_x < vAR_y)
# Output: x == y is False
print('vAR_x == vAR_y is',vAR_x==vAR_y)
# Output: x != y is True
print('vAR_x != vAR_y is',vAR_x!=vAR_y)
# Output: x >= y is False
print('vAR_x >= vAR_y is',vAR_x>=vAR_y)
# Output: x <= y is True
print('vAR_x <= vAR_y is',vAR_x<=vAR_y)
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
## Logical operators are the and, or, not operators
vAR_x = True
vAR_y = False
# Output: x and y is False
print('vAR_x and vAR_y is',vAR_x and vAR_y)
# Output: x or y is True
print('vAR_x or vAR_y is',vAR_x or vAR_y)
# Output: not x is False
print('not vAR_x is',not vAR_x)
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
## "is" and "is not" are the identity operators in Python.
## They are used to check if two values (or variables) are located on the same part of the memory.
## Two variables that are equal does not imply that they are identical.
vAR_x1 = 5
vAR_y1 = 5
vAR_x2 = 'Hello'
vAR_y2 = 'Hello'
vAR_x3 = [1,2,3]
vAR_y3 = [1,2,3]
# Output: False
print(vAR_x1 is not vAR_y1)
# Output: True
print(vAR_x2 is vAR_y2)
# Output: False
print(vAR_x3 is vAR_y3)
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
## "in" and "not" in are the membership operators in Python.
## They are used to test whether a value or variable is found in a sequence (string, list, tuple, set and dictionary).
vAR_x = 'Hello world'
vAR_y = {1:'a',2:'b'}
# Output: True
print('H' in vAR_x)
# Output: True
print('hello' not in vAR_x)
# Output: True
print(1 in vAR_y)
# Output: False
print('a' in vAR_y)
##>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_DECORATORS_V1
Purpose : A Program in Python for Decorators
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 12:44 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Decorators in Python
## Python Development Environment & Runtime - Python, Anaconda
def simple(*args):
for arg in args:
print (arg),
simple('a', 'b', 'c')
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_LIST_COMPREHENSIONS_V1
Purpose : A Program in Python for List Comprehensions
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 13:00 hrs
Version : 1.0
/****************************************
## Program Description : A Program for List Comprehensions in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_Celsius = [39.2, 36.5, 37.3, 37.8]
vAR_Fahrenheit = [ ((float(9)/5)*x + 32) for x in vAR_Celsius ]
print (vAR_Fahrenheit)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_GENERATOR_EXPRESSIONS_V1
Purpose : A Program in Python for Generator Expressions
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 13:47 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Generator Expressions in Python
## Python Development Environment & Runtime - Python, Anaconda
def my_gen():
for x in range(5):
yield x
vAR_gen_exp = (x ** 2 for x in range(10) if x % 2 == 0)
for x in gen_exp:
print(x)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/*******
File Name : CSLAB_GENERATOR_FUNCTIONS_V1
Purpose : A Program in Python for Generator Functions
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 14:23 hrs
Version : 1.0
/**************
## Program Description : A Program for Generator Functions in Python
## Python Development Environment & Runtime - Python, Anaconda
def vAR_CSLAB_fib(vAR_CSLAB_limit):
# Initialize first two Fibonacci Numbers
vAR_CSLAB_a, vAR_CSLAB_b = 0, 1
# One by one yield next Fibonacci Number
while vAR_CSLAB_a < vAR_CSLAB_limit:
yield vAR_CSLAB_a
vAR_CSLAB_a, vAR_CSLAB_b = vAR_CSLAB_b, vAR_CSLAB_a + vAR_CSLAB_b
# Create a generator object
vAR_CSLAB_x = vAR_CSLAB_fib(5)
# Iterating over the generator object using next
print(vAR_CSLAB_x. __next__() ); # In Python 3, __next__()
print(vAR_CSLAB_x. __next__() );
print(vAR_CSLAB_x. __next__() );
print(vAR_CSLAB_x. __next__() );
print(vAR_CSLAB_x. __next__() );
# Iterating over the generator object using for
# in loop.
print("\nUsing for in loop")
for i in vAR_CSLAB_fib(5):
print(i)
/*******
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******
/****************************************
File Name : CSLAB_ITERTOOLS_CHAIN_V1
Purpose : A Program in Python for Iter Tools - Chain()
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 15:58 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Iter Tools in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_l1 = ['a', 'b', 'c']
vAR_l2 = ['d', 'e', 'f']
vAR_l1.extend(vAR_l2)
vAR_l1
import itertools
vAR_l1 = ['a', 'b', 'c']
vAR_l2 = ['d', 'e', 'f']
vAR_chained = itertools.chain(vAR_l1, vAR_l2)
vAR_chained
[vAR_l for vAR_l in chained]
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_ITERTOOLS_IZIP_V1
Purpose : A Program in Python for Iter Tools - Izip()
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 16:29 hrs
Version : 1.0
/****************************************
## Program Description : A Program for Iter Tools - IZIP in Python
## Python Development Environment & Runtime - Python, Anaconda
name = ['Jimmy', 'Robert', 'John Paul', 'John']
instruments = ['Guitar', 'Vocals', 'Bass', 'Drums']
zepp = zip(name, instruments)
zepp
#zepp = itertools.islice(name, instruments)
#zepp
[musician for musician in zepp]
/**************************************************************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/****************************************
File Name : CSLAB_DEBUGGING_TOOL_PPRINT_V1
Purpose : A Program in Python for pprint
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 17:54 hrs
Version : 1.0
/****************************************
## Program Description : A Program for pprint in Python
## Python Development Environment & Runtime - Python, Anaconda
import pprint
deep = [{'letter': let, 'index': i, 'extended': let*i}
for i, let in enumerate(list('abcdefg'))]
deep
pprint.pprint(deep)
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/**************************
File Name : CSLAB_CLASSES_V1
Purpose : A Program in Python for Classes
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 9:43 hrs
Version : 1.0
/**************************
## Program Description : A Program for Classes in Python
## Python Development Environment & Runtime - Python, Anaconda
class A(object):
def whoami(self):
return self.__class__.__name__
vAR_A = A()
vAR_A
vAR_A.whoami()
/****************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/**************************************************************************************************
File Name : CSLAB_EMULATION_V1
Purpose : A Program in Python for Emulation
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 10:28 hrs
Version : 1.0
/**************************************************************************************************
## Program Description : A Program for Emulations in Python
## Python Development Environment & Runtime - Python, Anaconda
class Adder(object):
def __init__(self, extra):
self.extra = extra
def __call__(self, base):
return self.extra + base
add2 = Adder(2)
add2(3)
/**************************************************************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/*******************
File Name : CSLAB_CLASS_METHOD_V1
Purpose : A Program in Python for Class Method
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 11:04 hrs
Version : 1.0
/*******************
## Program Description : A Program for Class Method in Python
## Python Development Environment & Runtime - Python, Anaconda
class vAR_CSLAB_Person:
vAR_CSLAB_age = 25
def vAR_CSLAB_printAge(cls):
print('The age is:', cls.vAR_CSLAB_age)
# create printAge class method
vAR_CSLAB_Person.vAR_CSLAB_printAge = classmethod(vAR_CSLAB_Person.vAR_CSLAB_printAge)
vAR_CSLAB_Person.vAR_CSLAB_printAge()
/*******
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/**************
/*******************
File Name : CSLAB_STATIC_METHOD_V1
Purpose : A Program in Python for Static Method
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 11:38 hrs
Version : 1.0
/*******************
## Program Description : A Program for Static Method in Python
## Python Development Environment & Runtime - Python, Anaconda
class vAR_CSLAB_Mathematics:
def vAR_CSLAB_addNumbers(x, y):
return x + y
# create addNumbers static method
vAR_CSLAB_Mathematics.addNumbers = staticmethod(vAR_CSLAB_Mathematics.vAR_CSLAB_addNumbers)
print('The sum is:', vAR_CSLAB_Mathematics.vAR_CSLAB_addNumbers(5, 10))
/*******
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/**************
/*******************
File Name : CSLAB_INHERITANCE_V1
Purpose : A Program in Python for Inheritance
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 12:15 hrs
Version : 1.0
/**************************
## Program Description : A Program for Inheritance in Python
## Python Development Environment & Runtime - Python, Anaconda
class vAR_CSLAB_Person(object):
# Constructor
def __init__(self, name):
self.name = name
# To get name
def getName(self):
return self.name
# To check if this person is employee
def isEmployee(self):
return False
# Inherited or Sub class (Note Person in bracket)
class vAR_CSLAB_Employee(vAR_CSLAB_Person):
# Here we return true
def isEmployee(self):
return True
# Driver code
vAR_CSLAB_emp = vAR_CSLAB_Person("aaa1") # An Object of Person
print(vAR_CSLAB_emp.getName(), vAR_CSLAB_emp.isEmployee())
vAR_CSLAB_emp = vAR_CSLAB_Employee("bbb2") # An Object of Employee
print(vAR_CSLAB_emp.getName(), vAR_CSLAB_emp.isEmployee())
/*******
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******
Â
/**************************************************************************************************
File Name : CSLAB_ENCAPSULATION_V1
Purpose : A Program in Python for Encapsulation
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 12:52 hrs
Version : 1.0
/**************************
## Program Description : A Program for Encapsulation in Python
## Python Development Environment & Runtime - Python, Anaconda
import traceback
import sys
class Course(object):
def __init__(self, capacity):
self.capacity = capacity
self.enrolled = 0
def enroll(self):
self.enrolled += 1
def __getattr__(self, name):
if name == 'open':
return self.capacity - self.enrolled
else:
raise AttributeError('%s not found', name)
def __setattr__(self, name, value):
if name == 'open':
self.enrolled = self.capacity - value
else:
object.__setattr__(self, name, value)
def __str__(self):
return 'Enrolled: t{0}nCapacity:t{1}nOpen:t{2}'.format(
self.enrolled, self.capacity, self.open)
course=Course(12)
course.enroll()
course.enroll()
/**************************************************************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/******************************************************************************************************************
File Name : CSLAB_N_DIMENSIONAL_ARRAY_V1 Surya
Purpose : A Program in Python for N Dimensionsional Arrays
Author : DeepSphere.AI, Inc.
Date and Time : 12/13/2018 12:34 hrs
Version : 1.0
/******************************************
## Program Description : A Program for N Dimensional Arrays in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
CSLAB_X = np.array([[1, 2, 3], [4, 5, 6]], np.int32)
type(CSLAB_X)
print(CSLAB_X.shape[0])
print(CSLAB_X.dtype)
/**************************************************************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/****************************************
/******************************************************************************************************************
File Name : CSLAB_READING_WRITING_DATA_V1
Purpose : A Program in Python for Reading & Writing Data
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:32 hrs
Version : 1.0
/******************************************
## Program Description : Program for Reading & Writing Data in Python
## Python Development Environment & Runtime - Python, Anaconda
CSLAB_f = open("E:Python ExamplesPredicted.txt", 'r')
CSLAB_f.read()
CSLAB_f.write("E:Python ExamplesPredicted1.txt")
print(_)
/*******************************************************************************************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/**************************************
/******************************************************************************************************************
File Name : CSLAB_READING_DATA_FROM_CSV_V1
Purpose : A Program in Python for Reading Data from a CSV File
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 9:51 hrs
Version : 1.0
/******************************************
## Program Description : Program for Reading Data from a CSV File in Python
## Python Development Environment & Runtime - Python, Anaconda
import csv
CSLAB_f = open("E:Pythontrain_1.csv", 'r')
CSLAB_f.read()
print(_)
/*******************************************************************************************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/**************************************
/************************************
File Name : CSLAB_NORMALIZING_DATA_V1
Purpose : A Program in Python for Normalizing Data
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 10:42 hrs
Version : 1.0
/******************************************
## Program Description : Program for Normalizing Data in Python
## Python Development Environment & Runtime - Python, Anaconda
# Normalize the data attributes for the Iris dataset.
from sklearn.datasets import load_iris
from sklearn import preprocessing
# load the iris dataset
iris = load_iris()
print(iris.data.shape)
# separate the data from the target attributes
CSLAB_X = iris.data
CSLAB_Y = iris.target
# normalize the data attributes
normalized_CSLAB_X = preprocessing.normalize(CSLAB_X)
/************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/************************
/*************************
File Name : CSLAB_FORMATTING_DATA_V1
Purpose : A Program in Python for Formatting Data
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 11:13 hrs
Version : 1.0
/******************************************
## Program Description : Program for Formatting Data in Python
## Python Development Environment & Runtime - Python, Anaconda
CSLAB_Q = 459
CSLAB_P = 0.098
print(CSLAB_Q, CSLAB_P, CSLAB_P * CSLAB_Q)
print(CSLAB_Q, CSLAB_P, CSLAB_P * CSLAB_Q, sep=",")
print(CSLAB_Q, CSLAB_P, CSLAB_P * CSLAB_Q, sep=" :-) ")
/************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/************************
/*************************
File Name : CSLAB_CONTROLLING_LINE_PROPERTIES_MATPLOTLIB_V1
Purpose : A Program in Python for Line Properties using Matplotlib Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 11:28 hrs
Version : 1.0
/******************************************
## Program Description : Program for Line Properties using Matplotlib Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import matplotlib.pyplot as plt
plt.plot([1,2,3,4], color='r', linewidth = 2.0)
plt.ylabel('some numbers')
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_PLOTTING_SIMPLE_FUNCTION_V1
Purpose : A Program in Python for Plotting Simple Function
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 9:28 hrs
Version : 1.0
/******************************************
## Program Description : Program for Plotting Simple Function in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
x=arange(0,2,0.01)
y=2*sin(2*pi*(x-1/4))
ylabel('y-axis')
xlabel('x-axis')
title(r'$y=2sin 2pi(x-1/4)$')
plot(x,y)
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/*******
File Name : CSLAB_IMPORTING_MODULE_V1
Purpose : A Program in Python for Importing a Module
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:22 hrs
Version : 1.0
/****************************************
## Program Description : Program for Importing a Module in Python
## Python Development Environment & Runtime - Python, Anaconda
import collections
import pprint
d = collections.deque()
d.append('a')
d.appendleft('b')
pprint.pprint(globals())
/*******
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******
/*******
File Name : CSLAB_CREATING_MODULE_V1
Purpose : A Program in Python for Creating Module
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:22 hrs
Version : 1.0
/****************************************
## Program Description : Program for Creating a Module in Python
## Python Development Environment & Runtime - Python, Anaconda
def shorten(toolong): return toolong[:2]
from tools import shorten
print (shorten('abcdef'))
/*******
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_USING_DEFAULTS_V1
Purpose : A Program in Python for Using Defaults in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 13:08 hrs
Version : 1.0
/***********************************
## Program Description : Program for Using Defaults in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
C,S = np.cos(X), np.sin(X)
plot(X,C)
plot(X,S)
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : XGRAPHING_MATPLOTLIB_USING_DEFAULTS_CHANGING_COLORS_V1
Purpose : A Program in Python for For Using Defaults & changing Line Color & Width in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 13:42 hrs
Version : 1.0
/***********************************
## Program Description : Program for Using Defaults & changing Line Color & Width in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
C,S = np.cos(X), np.sin(X)
plot(X,C)
plot(X,S)
figure(figsize=(10,6), dpi=80)
plot(X, C, color="blue", linewidth=2.5, linestyle="-")
plot(X, S, color="red", linewidth=2.5, linestyle="-")
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_USING_DEFAULTS_SETTING_LIMITS_V1
Purpose : A Program in Python for Using & Setting Defaults in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 10:00 hrs
Version : 1.0
/****************************************
## Program Description : Program Using & Defaults in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
import numpy as vAR_np
vAR_CSLAB_X = vAR_np.linspace(-vAR_np.pi, vAR_np.pi, 256,endpoint=True)
vAR_CSLAB_C,vAR_CSLAB_S = vAR_np.cos(vAR_CSLAB_X), vAR_np.sin(vAR_CSLAB_X)
plot(vAR_CSLAB_X,vAR_CSLAB_C)
plot(vAR_CSLAB_X,vAR_CSLAB_S)
xlim(-4.0,4.0)
ylim(-1.0,1.0)
xlim(vAR_CSLAB_X.min()*1.1, vAR_CSLAB_X.max()*1.1)
ylim(vAR_CSLAB_C.min()*1.1, vAR_CSLAB_C.max()*1.1)
xmin ,xmax = vAR_CSLAB_X.min(), vAR_CSLAB_X.max()
dx = (xmax - xmin) * 0.2
xlim(xmin - dx, xmax + dx)
show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_USING_DEFAULTS_SETTING_TICKS_V1
Purpose : A Program in Python for Using Defaults & Setting Ticks in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 10:25 hrs
Version : 1.0
/***********************************
## Program Description : Program for Using Defaults & Setting Ticks in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
C,S = np.cos(X), np.sin(X)
plot(X,C)
plot(X,S)
xlim(-4.0,4.0)
ylim(-1.0,1.0)
xlim(X.min()*1.1, X.max()*1.1)
ylim(C.min()*1.1, C.max()*1.1)
xmin ,xmax = X.min(), X.max()
dx = (xmax - xmin) * 0.2
xlim(xmin - dx, xmax + dx)
xticks( [-np.pi, -np.pi/2, 0, np.pi/2, np.pi])
yticks([-1, 0, +1])
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_USING_DEFAULTS_SETTING_TICK_LABELS_V1
Purpose : A Program in Python for Using Defaults & Setting Tick Labels in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 11:02 hrs
Version : 1.0
/***********************************
## Program Description : Program for Using Defaults & Setting Tick Labels in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
C,S = np.cos(X), np.sin(X)
plot(X,C)
plot(X,S)
xlim(-4.0,4.0)
ylim(-1.0,1.0)
xlim(X.min()*1.1, X.max()*1.1)
ylim(C.min()*1.1, C.max()*1.1)
xmin ,xmax = X.min(), X.max()
dx = (xmax - xmin) * 0.2
xlim(xmin - dx, xmax + dx)
xticks( [-np.pi, -np.pi/2, 0, np.pi/2, np.pi])
yticks([-1, 0, +1])
xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi],
[r'$-pi$', r'$-pi/2$', r'$0$', r'$+pi/2$', r'$+pi$'])
yticks([-1, 0, +1],
[r'$-1$', r'$0$', r'$+1$'])
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_USING_DEFAULTS_MOVING_SPINES_V1
Purpose : A Program in Python for Using Defaults & Moving Spines in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 11:39 hrs
Version : 1.0
/***********************************
## Program Description : Program for Using Defaults & Moving Spines in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
C,S = np.cos(X), np.sin(X)
plot(X,C)
plot(X,S)
xlim(-4.0,4.0)
ylim(-1.0,1.0)
xlim(X.min()*1.1, X.max()*1.1)
ylim(C.min()*1.1, C.max()*1.1)
xmin ,xmax = X.min(), X.max()
dx = (xmax - xmin) * 0.2
xlim(xmin - dx, xmax + dx)
xticks( [-np.pi, -np.pi/2, 0, np.pi/2, np.pi])
yticks([-1, 0, +1])
xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi],
[r'$-pi$', r'$-pi/2$', r'$0$', r'$+pi/2$', r'$+pi$'])
yticks([-1, 0, +1],
[r'$-1$', r'$0$', r'$+1$'])
ax = gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_USING_DEFAULTS_ADDING_LEGENDS_V1
Purpose : A Program in Python for Using Defaults & Adding Legends in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:05 hrs
Version : 1.0
/***********************************
## Program Description : Program for Using Defaults & Adding Legends in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
C,S = np.cos(X), np.sin(X)
plot(X,C)
plot(X,S)
xlim(-4.0,4.0)
ylim(-1.0,1.0)
xlim(X.min()*1.1, X.max()*1.1)
ylim(C.min()*1.1, C.max()*1.1)
xmin ,xmax = X.min(), X.max()
dx = (xmax - xmin) * 0.2
xlim(xmin - dx, xmax + dx)
xticks( [-np.pi, -np.pi/2, 0, np.pi/2, np.pi])
yticks([-1, 0, +1])
xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi],
[r'$-pi$', r'$-pi/2$', r'$0$', r'$+pi/2$', r'$+pi$'])
yticks([-1, 0, +1],
[r'$-1$', r'$0$', r'$+1$'])
ax = gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))
plot(X, C, color="blue", linewidth=2.5, linestyle="-", label="cosine")
plot(X, S, color="red", linewidth=2.5, linestyle="-", label="sine")
legend(loc='upper left')
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_USING_DEFAULTS_ANNOTATING_POINTS_LEGENDS_V1
Purpose : A Program in Python for Using Defaults & Annota in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:05 hrs
Version : 1.0
/***********************************
## Program Description : Program for Using Defaults & Annota in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
C,S = np.cos(X), np.sin(X)
plot(X,C)
plot(X,S)
xlim(-4.0,4.0)
ylim(-1.0,1.0)
xlim(X.min()*1.1, X.max()*1.1)
ylim(C.min()*1.1, C.max()*1.1)
xmin ,xmax = X.min(), X.max()
dx = (xmax - xmin) * 0.2
xlim(xmin - dx, xmax + dx)
xticks( [-np.pi, -np.pi/2, 0, np.pi/2, np.pi])
yticks([-1, 0, +1])
xticks([-np.pi, -np.pi/2, 0, np.pi/2, np.pi],
[r'$-pi$', r'$-pi/2$', r'$0$', r'$+pi/2$', r'$+pi$'])
yticks([-1, 0, +1],
[r'$-1$', r'$0$', r'$+1$'])
ax = gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))
plot(X, C, color="blue", linewidth=2.5, linestyle="-", label="cosine")
plot(X, S, color="red", linewidth=2.5, linestyle="-", label="sine")
legend(loc='upper left')
t = 2*np.pi/3
plot([t,t],[0,np.cos(t)], color ='blue', linewidth=2.5, linestyle="--")
scatter([t,],[np.cos(t),], 50, color ='blue')
annotate(r'$sin(frac{2pi}{3})=frac{sqrt{3}}{2}$',
xy=(t, np.sin(t)), xycoords='data',
xytext=(+10, +30), textcoords='offset points', fontsize=16,
arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2"))
plot([t,t],[0,np.sin(t)], color ='red', linewidth=2.5, linestyle="--")
scatter([t,],[np.sin(t),], 50, color ='red')
annotate(r'$cos(frac{2pi}{3})=-frac{1}{2}$',
xy=(t, np.cos(t)), xycoords='data',
xytext=(-90, -50), textcoords='offset points', fontsize=16,
arrowprops=dict(arrowstyle="->", connectionstyle="arc3,rad=.2"))
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_DATA_MANIPULATION_USING_V1
Purpose : A Program in Python for Data Manipulation using Pandas
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 13:42 hrs
Version : 1.0
/******************************************
## Program Description : Program for Data Manipulation using Pandas in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as pd
import numpy as np
import matplotlib as plt
CSLAB_DF = pd.read_csv("C:/Users/user/Desktop/CSLAB_CUSTOMER.csv")
CSLAB_DF.head(10)
CSLAB_DF.describe()
CSLAB_FIGURE = plt.pyplot.figure()
CSLAB_FIGURE = plt.pyplot.figure()
CSLAB_AX = CSLAB_FIGURE.add_subplot(111)
CSLAB_AX.hist(CSLAB_DF['Customer_ID'], bins = 10, range = (CSLAB_DF['Customer_ID'].min(),CSLAB_DF['Customer_ID'].max()))
plt.pyplot.title('Sales Analysis')
plt.pyplot.xlabel('Customer_ID')
plt.pyplot.ylabel('Amount')
plt.pyplot.show()
from pylab import *
CSLAB_AX = axes([0.1, 0.1, 0.8, 0.8])
CSLAB_labels = 'Nicholas', 'Nasser', 'Elizabeth', 'William', 'Johan'
CSLAB_fracs = [10, 20, 25, 25, 20]
CSLAB_explode=(0, 0.05, 0, 0)
pie(CSLAB_fracs, explode=CSLAB_explode, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)
title('Customer Churn % ', bbox={'facecolor':'0.8', 'pad':5})
show()
import matplotlib.pyplot as plt
plt.plot([1124,1958,857,2465,3042,3245,4544,4956,3896,4948,4565])
plt.ylabel('Amount($)')
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/*******
File Name : CSLAB_READING_DATA_FROM_HANA_TO_PYTHON
Purpose : A Program in Python for Reading Data from SAP HANA
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 17:00 hrs
Version : 1.0
/*******
## Program Description : Program for Reading Data from SAP HANA in Python
## Python Development Environment & Runtime - Python, Anaconda
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pypyodbc as pyodbc
CSLAB_CONN = pyodbc.connect('DSN=DS;UID=DURGA;PWD=Delhi123')
CSLAB_CURSOR = CSLAB_CONN.cursor()
CSLAB_STMNT = 'SELECT * FROM DURGA.TICKETS'
CSLAB_CURSOR.execute(CSLAB_STMNT)
CSLAB_RESULT = CSLAB_CURSOR.fetchall()
print (CSLAB_RESULT)
/*******
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk.
All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******
/************************************
File Name : CSLAB_DIFFERENTIAL_EXPRESSION_ANALYSIS_V1
Purpose : A Program in Python for Differential Expression Analysis using statsmodels Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:31 hrs
Version : 1.0
/******************************************
## Program Description : Program for Differential Expression Analysis using statsmodels Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import gzip
import numpy as np
import urllib2
import gzip
from StringIO import StringIO
from statsmodels.stats.multitest import multipletests
from scipy.stats.distributions import norm
import matplotlib.pyplot as plt
url = urllib2.urlopen("ftp://ftp.ncbi.nlm.nih.gov/geo/datasets/GDS1nnn/GDS1615/soft/GDS1615_full.soft.gz")
zdata = url.read()
sio = StringIO(zdata)
fid = gzip.GzipFile(fileobj=sio)
SIF = {}
for line in fid:
if line.startswith("!dataset_table_begin"):
break
elif line.startswith("!subset_description"):
subset_description = line.split("=")[1].strip()
elif line.startswith("!subset_sample_id"):
subset_ids = line.split("=")[1].split(",")
subset_ids = [x.strip() for x in subset_ids]
for k in subset_ids:
SIF[k] = subset_description
# Next line is the column headers (sample id's)
SID = fid.next().split("t")
# The column indices that contain gene expression data
I = [i for i,x in enumerate(SID) if x.startswith("GSM")]
# Restrict the column headers to those that we keep
SID = [SID[i] for i in I]
# Get a list of sample labels
STP = [SIF[k] for k in SID]
# Read the gene expression data as a list of lists, also get the gene identifiers
GID,X = [],[]
for line in fid:
# This is what signals the end of the gene expression data
# section in the file
if line.startswith("!dataset_table_end"):
break
V = line.split("t")
# Extract the values that correspond to gene expression measures
# and convert the strings to numbers
x = [float(V[i]) for i in I]
X.append(np.asarray(x))
GID.append(V[0] + ";" + V[1])
# Convert the Python list of lists to a Numpy array.
X = np.asarray(X)
# The indices of samples for the ulcerative colitis group
UC = [i for i,x in enumerate(STP) if x == "ulcerative colitis"]
# The indices of samples for the Crohn's disease group
CD = [i for i,x in enumerate(STP) if x == "Crohn's disease"]
XL = np.log(X) / np.log(2)
MUC = XL[:,UC].mean(1) ## Mean of ulcerative colitis samples
MCD = XL[:,CD].mean(1) ## Mean of Crohn's disease samples
VUC = XL[:,UC].var(1) ## Variance of ulcerative colitis samples
VCD = XL[:,CD].var(1) ## Variance of Crohn's disease samples
nUC = len(UC) ## Number of ulcerative colitis samples
nCD = len(CD) ## Number of Crohn's disease samples
zscores = (MUC - MCD) / np.sqrt(VUC/nUC + VCD/nCD)
print zscores.mean()
print zscores.std()
print np.mean(np.abs(zscores) > 2)
print np.mean(zscores > 2)
print np.mean(zscores < -2)
pvalues = 2*norm.cdf(-np.abs(zscores))
pm = multipletests(pvalues, method="fdr_bh")
apv = pm[1]
ii = np.argsort(zscores)
plt.plot(zscores[ii], apv[ii], '-')
plt.xlabel("Z-score")
plt.ylabel("False Discovery Rate")
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_GENERALIZED_LINEAR_MODELS_V1
Purpose : A Program in Python for Generalized Linear Models using statsmodels Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 13:44 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Generalized Linear Models using statsmodels Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
import pandas as vAR_pd
import matplotlib.pyplot as vAR_plt
from statsmodels.discrete.discrete_model import Logit
import os
vAR_INI_File_Path = os.environ.get('PYTHON_TUTORIAL')
import pandas as vAR_pd
import configparser
import pandas as vAR_pd
vAR_Config = configparser.ConfigParser(allow_no_value=True)
vAR_Config.read(vAR_INI_File_Path)
vAR_CSLAB_Data_URL1 = vAR_Config['Data File Path']['vAR_CSLAB_PROGRAM_70_DATA_URL1']
vAR_CSLAB_Data_URL1 = vAR_CSLAB_Data_URL1
vAR_CSLAB_data_tr = vAR_pd.read_csv(vAR_CSLAB_Data_URL1)
vAR_CSLAB_Data_URL2 = vAR_Config['Data File Path']['vAR_CSLAB_PROGRAM_70_DATA_URL2']
vAR_CSLAB_Data_URL2 = vAR_CSLAB_Data_URL2
vAR_CSLAB_data_te = vAR_pd.read_csv(vAR_CSLAB_Data_URL2)
vAR_CSLAB_data = vAR_pd.concat((vAR_CSLAB_data_tr, vAR_CSLAB_data_te), axis=0)
vAR_CSLAB_endog = vAR_np.asarray([int(x.lower() == "yes") for x in vAR_CSLAB_data["type"]])
vAR_CSLAB_xnames = ["npreg", "glu", "bp", "skin", "bmi", "ped", "age"]
vAR_CSLAB_exog = vAR_np.asarray(vAR_CSLAB_data[vAR_CSLAB_xnames])
vAR_CSLAB_exog = vAR_np.concatenate((vAR_np.ones((vAR_CSLAB_exog.shape[0],1)), vAR_CSLAB_exog), axis=1)
vAR_CSLAB_x = [vAR_np.corrcoef(vAR_CSLAB_endog, vAR_CSLAB_x)[0,1] for vAR_CSLAB_x in vAR_CSLAB_exog[:,1:].T]
vAR_CSLAB_x = vAR_pd.Series(vAR_CSLAB_x, index=vAR_CSLAB_xnames)
print(vAR_CSLAB_x)
vAR_CSLAB_n = vAR_CSLAB_data.shape[0]
vAR_CSLAB_scores = vAR_np.zeros(vAR_CSLAB_n, dtype=vAR_np.float64)
for k in range(vAR_CSLAB_n):
vAR_CSLAB_ii = range(vAR_CSLAB_n)
#ii.pop(k)
vAR_CSLAB_mod = Logit(vAR_CSLAB_endog[vAR_CSLAB_ii], vAR_CSLAB_exog[vAR_CSLAB_ii,:])
vAR_CSLAB_rslt = vAR_CSLAB_mod.fit(disp=False)
vAR_CSLAB_scores[k] = vAR_CSLAB_rslt.predict(vAR_CSLAB_exog[k,:])
vAR_CSLAB_uscores = vAR_np.unique(vAR_CSLAB_scores)
vAR_CSLAB_n1 = vAR_np.sum(vAR_CSLAB_endog)
vAR_CSLAB_Sens = vAR_np.zeros_like(vAR_CSLAB_uscores)
vAR_CSLAB_Spec = vAR_np.zeros_like(vAR_CSLAB_uscores)
for j,u in enumerate(vAR_CSLAB_uscores):
vAR_CSLAB_Sens[j] = vAR_np.sum((vAR_CSLAB_scores >= u) * vAR_CSLAB_endog) / float(vAR_CSLAB_n1)
vAR_CSLAB_Spec[j] = vAR_np.sum((vAR_CSLAB_scores <= u) * (1-vAR_CSLAB_endog)) / float(vAR_CSLAB_n - vAR_CSLAB_n1)
vAR_plt.plot(1 - vAR_CSLAB_Spec, vAR_CSLAB_Sens, '-')
vAR_plt.plot([0,1], [0,1], '-', color='grey')
vAR_plt.xlabel("1 - Specificity", size=17)
vAR_plt.ylabel("Sensitivity", size=17)
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_DOT_PLOT_V1
Purpose : A Program in Python for Dot Plots using statsmodels Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:07 hrs
Version : 1.0
/******************************************
## Program Description : Program for Dot Plots using statsmodels Package in Python
## Python Development Environment & Runtime - Python, Anaconda
from statsmodels.graphics.dotplots import dot_plot
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data_url = "https://umich.box.com/shared/static/uxpesc1pix3gedyecggp.csv"
data = pd.read_csv(data_url)
print data.head()
small = data.iloc[0:10,:]
fig = dot_plot(points=small["2000 GDP"])
plt.xlabel("GDP", size=16)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_FERTILITY_TRENDS_V1
Purpose : A Program in Python for Fertility Trends using statsmodels Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:54 hrs
Version : 1.0
/******************************************
## Program Description : Program for Dot Plots using statsmodels Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from statsmodels.sandbox.tools.tools_pca import pcasvd
url = "C:UsersuserDownloadssp.dyn.tfrt.in_Indicator_en_csv_v2.csv"
data = pd.read_csv(url, skiprows=2)
print data.head()
for tok in ["IFC", "developing", "income", "European", "HIPC", "classified",
"Least", "Other", "small states", "cone", "world", "baltics"]:
ii = [i for i in data.index if tok.lower() in data.loc[i, "Country Name"].lower()]
print "n".join(data.loc[ii, "Country Name"])
data = data.drop(ii)
years = range(1960, 2012)
years_str = ["%.0f" % y for y in years]
mat = data.loc[:, ["Country Name",] + years_str].dropna()
countries = mat["Country Name"].tolist()
mat = np.asarray(mat.loc[:, years_str])
plt.clf()
mn = mat.mean(0)
plt.plot(years, mn, '-', lw=4)
plt.grid(True)
plt.xlabel("Year", size=17)
plt.ylabel("Global mean fertility rate", size=17)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_LOGISTIC_REGRESSION_V1
Purpose : A Program in Python for Logistic Regression using statsmodels Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 16:54 hrs
Version : 1.0
/******************************************
## Program Description : Program for Logistic Regression using statsmodels Package in Python
## Python Development Environment & Runtime - Python, Anaconda
from statsmodels.discrete.discrete_model import Logit
import numpy as np
import matplotlib.pyplot as plt
CSLAB_n = 200
CSLAB_p = 10
exog = np.random.normal(size=(CSLAB_n,CSLAB_p))
lpred = exog[:,0] + 0.5*exog[:,1] - 0.5*exog[:,2]
prob = 1 / (1 + np.exp(-lpred))
endog = 1*(np.random.uniform(size=n) <= prob)
mod = Logit(endog, exog)
rslt1 = mod.fit()
print rslt1.summary()
rslt2 = mod.fit_regularized(alpha=10, disp=False)
print rslt2.summary()
alpha = np.linspace(0, 50, 50)
params = []
for a in alpha:
rslt2 = mod.fit_regularized(alpha=a, disp=False)
params.append(rslt2.params)
params = np.asarray(params)
plt.clf()
cmap = {0: "red", 1: "green", 2: "blue"}
for k in range(10):
color = 'grey'
if k in (0, 1, 2):
color = cmap[k]
plt.plot(alpha, params[:,k], color=color)
plt.xlabel("Penalty weight", size=17)
plt.ylabel("Coefficient", size=17)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_SPARSE_MODELS_V1
Purpose : A Program in Python Sparse Models
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 18:19 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Sparse Models in Python
## Python Development Environment & Runtime - Python, Anaconda
import warnings
import matplotlib.pyplot as vAR_plt
import numpy as vAR_np
from scipy import linalg
from sklearn.linear_model import (RandomizedLasso, lasso_stability_path,
LassoLarsCV)
from sklearn.feature_selection import f_regression
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import auc, precision_recall_curve
from sklearn.ensemble import ExtraTreesRegressor
from sklearn.utils.extmath import pinvh
#from sklearn.utils import ConvergenceWarning
def mutual_incoherence(X_relevant, X_irelevant):
vAR_CSLAB_projector = vAR_np.dot(vAR_np.dot(X_irelevant.T, X_relevant),
pinvh(vAR_np.dot(X_relevant.T, X_relevant)))
return vAR_np.max(vAR_np.abs(vAR_CSLAB_projector).sum(axis=1))
for conditioning in (1, 1e-4):
vAR_CSLAB_n_features = 501
vAR_CSLAB_n_relevant_features = 3
vAR_CSLAB_noise_level = .2
vAR_CSLAB_coef_min = .2
vAR_CSLAB_n_samples = 25
vAR_CSLAB_block_size = vAR_CSLAB_n_relevant_features
vAR_CSLAB_rng = vAR_np.random.RandomState(42)
vAR_CSLAB_coef = vAR_np.zeros(vAR_CSLAB_n_features)
vAR_CSLAB_coef[:vAR_CSLAB_n_relevant_features] = vAR_CSLAB_coef_min + vAR_CSLAB_rng.rand(vAR_CSLAB_n_relevant_features)
vAR_CSLAB_corr = vAR_np.zeros((vAR_CSLAB_n_features, vAR_CSLAB_n_features))
for i in range(0, vAR_CSLAB_n_features, vAR_CSLAB_block_size):
vAR_CSLAB_corr[i:i + vAR_CSLAB_block_size, i:i + vAR_CSLAB_block_size] = 1 - conditioning
vAR_CSLAB_corr.flat[::vAR_CSLAB_n_features + 1] = 1
vAR_CSLAB_corr = linalg.cholesky(vAR_CSLAB_corr)
vAR_CSLAB_X = vAR_CSLAB_rng.normal(size=(vAR_CSLAB_n_samples, vAR_CSLAB_n_features))
vAR_CSLAB_X = vAR_np.dot(vAR_CSLAB_X, vAR_CSLAB_corr)
# Keep [Wainwright2006] (26c) constant
vAR_CSLAB_X[:vAR_CSLAB_n_relevant_features] /= vAR_np.abs(
linalg.svdvals(vAR_CSLAB_X[:vAR_CSLAB_n_relevant_features])).max()
vAR_CSLAB_X = StandardScaler().fit_transform(vAR_CSLAB_X.copy())
# The output variable
vAR_CSLAB_y = vAR_np.dot(vAR_CSLAB_X, vAR_CSLAB_coef)
vAR_CSLAB_y /= vAR_np.std(vAR_CSLAB_y)
vAR_CSLAB_y += vAR_CSLAB_noise_level * vAR_CSLAB_rng.normal(size=vAR_CSLAB_n_samples)
vAR_CSLAB_mi = mutual_incoherence(vAR_CSLAB_X[:, :vAR_CSLAB_n_relevant_features],
vAR_CSLAB_X[:, vAR_CSLAB_n_relevant_features:])
vAR_CSLAB_alpha_grid, vAR_CSLAB_scores_path = lasso_stability_path(vAR_CSLAB_X, vAR_CSLAB_y, random_state=42,
eps=0.05)
vAR_plt.figure()
vAR_CSLAB_hg = vAR_plt.plot(vAR_CSLAB_alpha_grid[1:] ** .333, vAR_CSLAB_scores_path[vAR_CSLAB_coef != 0].T[1:], 'r')
vAR_CSLAB_hb = vAR_plt.plot(vAR_CSLAB_alpha_grid[1:] ** .333, vAR_CSLAB_scores_path[vAR_CSLAB_coef == 0].T[1:], 'k')
vAR_CSLAB_ymin, vAR_CSLAB_ymax = vAR_plt.ylim()
vAR_plt.xlabel(r'$(\alpha / \alpha_{max})^{1/3}$')
vAR_plt.ylabel('Stability score: proportion of times selected')
vAR_plt.title('Stability Scores Path - Mutual incoherence: %.1f' % vAR_CSLAB_mi)
vAR_plt.axis('tight')
vAR_plt.legend((vAR_CSLAB_hg[0], vAR_CSLAB_hb[0]), ('relevant features', 'irrelevant features'),
loc='best')
vAR_CSLAB_lars_cv = LassoLarsCV(cv=6).fit(vAR_CSLAB_X, vAR_CSLAB_y)
vAR_CSLAB_alphas = vAR_np.linspace(vAR_CSLAB_lars_cv.alphas_[0], .1 * vAR_CSLAB_lars_cv.alphas_[0], 6)
vAR_CSLAB_clf = RandomizedLasso(alpha=vAR_CSLAB_alphas, random_state=42).fit(vAR_CSLAB_X, vAR_CSLAB_y)
vAR_CSLAB_trees = ExtraTreesRegressor(100).fit(vAR_CSLAB_X, vAR_CSLAB_y)
# Compare with F-score
vAR_CSLAB_F, _ = f_regression(vAR_CSLAB_X, vAR_CSLAB_y)
vAR_plt.figure()
for vAR_CSLAB_name, vAR_CSLAB_score in [('F-test', vAR_CSLAB_F),
('Stability selection', vAR_CSLAB_clf.scores_),
('Lasso coefs', vAR_np.abs(vAR_CSLAB_lars_cv.coef_)),
('Trees', vAR_CSLAB_trees.feature_importances_),
]:
vAR_CSLAB_precision, vAR_CSLAB_recall, vAR_CSLAB_thresholds = precision_recall_curve(vAR_CSLAB_coef != 0,
vAR_CSLAB_score)
vAR_plt.semilogy(vAR_np.maximum(vAR_CSLAB_score / vAR_np.max(vAR_CSLAB_score), 1e-4),
label="%s. AUC: %.3f" % (vAR_CSLAB_name, auc(vAR_CSLAB_recall, vAR_CSLAB_precision)))
vAR_plt.plot(vAR_np.where(vAR_CSLAB_coef != 0)[0], [2e-4] * vAR_CSLAB_n_relevant_features, 'mo',
label="Ground truth")
vAR_plt.xlabel("Features")
vAR_plt.ylabel("Score")
vAR_plt.xlim(0, 100)
vAR_plt.legend(loc='best')
vAR_plt.title('Feature selection scores - Mutual incoherence: %.1f'
% vAR_CSLAB_mi)
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_CROSS_VALIDATION_MODELS_V1
Purpose : A Program in Python Cross Validation Models
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 18:37 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Cross Validation Models in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
import sklearn
from sklearn import datasets
from sklearn import svm
vAR_CSLAB_iris = datasets.load_iris()
print(vAR_CSLAB_iris.data.shape, vAR_CSLAB_iris.target.shape)
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_SVM_MODEL_V1
Purpose : A Program in Python for SVM Model SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 19:01 hrs
Version : 1.0
/******************************************
## Program Description : Program for SVM in Python
## Python Development Environment & Runtime - Python, Anaconda
from sklearn import svm
X = [[0, 0], [1, 1]]
y = [0, 1]
clf = svm.SVC()
clf.fit(X, y)
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape=None, degree=3, gamma='auto', kernel='rbf',
max_iter=-1, probability=False, random_state=None, shrinking=True,
tol=0.001, verbose=False)
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SVM_MODEL_MULTICLASS_CLASSIFICATION_V1
Purpose : A Program in Python for SVM Multiclass Classification Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 19:23 hrs
Version : 1.0
/******************************************
## Program Description : Program for SVM Multiclass Classification in Python
## Python Development Environment & Runtime - Python, Anaconda
X = [[0], [1], [2], [3]]
Y = [0, 1, 2, 3]
clf = svm.SVC(decision_function_shape='ovo')
clf.fit(X, Y)
SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.0,
decision_function_shape='ovo', degree=3, gamma='auto', kernel='rbf',
max_iter=-1, probability=False, random_state=None, shrinking=True,
tol=0.001, verbose=False)
dec = clf.decision_function([[1]])
dec.shape[1] # 4 classes: 4*3/2 = 6
clf.decision_function_shape = "ovr"
dec = clf.decision_function([[1]])
dec.shape[1] # 4 classes
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_SVM_MODEL_SPECIES_DISTRIBUTION_V1
Purpose : A Program in Python for Species Distribution Model Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : for Species Distribution Model 19:58 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Species Distribution Model in Python
## Python Development Environment & Runtime - Python, Anaconda
from __future__ import print_function
from time import time
import numpy as vAR_np
import matplotlib.pyplot as vAR_plt
from sklearn.datasets.base import Bunch
from sklearn.datasets import fetch_species_distributions
from sklearn.datasets.species_distributions import construct_grids
from sklearn import svm, metrics
%matplotlib notebook
try:
from mpl_toolkits.basemap import Basemap
basemap = True
except ImportError:
basemap = False
print(__doc__)
def create_species_bunch(species_name, train, test, coverages, xgrid, ygrid):
vAR_CSLAB_bunch = Bunch(name=' '.join(species_name.split("_")[:2]))
vAR_CSLAB_species_name = species_name.encode('ascii')
vAR_CSLAB_points = dict(test=test, train=train)
for label, pts in vAR_CSLAB_points.items():
# choose points associated with the desired species
pts = pts[pts['species'] == vAR_CSLAB_species_name]
vAR_CSLAB_bunch['pts_%s' % label] = pts
# determine coverage values for each of the training & testing points
ix = vAR_np.searchsorted(xgrid, pts['dd long'])
iy = vAR_np.searchsorted(ygrid, pts['dd lat'])
vAR_CSLAB_bunch['cov_%s' % label] = coverages[:, -iy, ix].T
return vAR_CSLAB_bunch
def plot_species_distribution(species=("bradypus_variegatus_0",
"microryzomys_minutus_0")):
if len(species) > 2:
print("Note: when more than two species are provided,"
" only the first two will be used")
vAR_CSLAB_t0 = time()
# Load the compressed data
vAR_CSLAB_data = fetch_species_distributions()
# Set up the data grid
xgrid, ygrid = construct_grids(vAR_CSLAB_data)
# The grid in x,y coordinates
X, Y = vAR_np.meshgrid(xgrid, ygrid[::-1])
# create a bunch for each species
vAR_CSLAB_BV_bunch = create_species_bunch(species[0],
vAR_CSLAB_data.train, vAR_CSLAB_data.test,
vAR_CSLAB_data.coverages, xgrid, ygrid)
vAR_CSLAB_MM_bunch = create_species_bunch(species[1],
vAR_CSLAB_data.train, vAR_CSLAB_data.test,
vAR_CSLAB_data.coverages, xgrid, ygrid)
# background points (grid coordinates) for evaluation
vAR_np.random.seed(13)
background_points = vAR_np.c_[vAR_np.random.randint(low=0, high=vAR_CSLAB_data.Ny,
size=10000),
vAR_np.random.randint(low=0, high=vAR_CSLAB_data.Nx,
size=10000)].T
# We'll make use of the fact that coverages[6] has measurements at all
# land points. This will help us decide between land and water.
vAR_CSLAB_land_reference = vAR_CSLAB_data.coverages[6]
# Fit, predict, and plot for each species.
for i, species in enumerate([vAR_CSLAB_BV_bunch, vAR_CSLAB_MM_bunch]):
print("_" * 80)
print("Modeling distribution of species '%s'" % species.name)
# Standardize features
vAR_CSLAB_mean = species.cov_train.mean(axis=0)
vAR_CSLAB_std = species.cov_train.std(axis=0)
vAR_CSLAB_train_cover_std = (species.cov_train - vAR_CSLAB_mean) / vAR_CSLAB_std
# Fit OneClassSVM
print(" - fit OneClassSVM ... ", end='')
vAR_CSLAB_clf = svm.OneClassSVM(nu=0.1, kernel="rbf", gamma=0.5)
vAR_CSLAB_clf.fit(vAR_CSLAB_train_cover_std)
print("done.")
# Plot map of South America
vAR_plt.subplot(1, 2, i + 1)
if basemap:
print(" - plot coastlines using basemap")
vAR_CSLAB_m = Basemap(projection='cyl', llcrnrlat=Y.min(),
urcrnrlat=Y.max(), llcrnrlon=X.min(),
urcrnrlon=X.max(), resolution='c')
vAR_CSLAB_m.drawcoastlines()
vAR_CSLAB_m.drawcountries()
else:
print(" - plot coastlines from coverage")
vAR_plt.contour(X, Y, vAR_CSLAB_land_reference,
levels=[-9999], colors="k",
linestyles="solid")
vAR_plt.xticks([])
vAR_plt.yticks([])
print(" - predict species distribution")
# Predict species distribution using the training data
vAR_CSLAB_Z = vAR_np.ones((vAR_CSLAB_data.Ny, vAR_CSLAB_data.Nx), dtype=vAR_np.float64)
# We'll predict only for the land points.
idx = vAR_np.where(vAR_CSLAB_land_reference > -9999)
vAR_CSLAB_coverages_land = vAR_CSLAB_data.coverages[:, idx[0], idx[1]].T
vAR_CSLAB_pred = vAR_CSLAB_clf.decision_function((vAR_CSLAB_coverages_land - vAR_CSLAB_mean) / vAR_CSLAB_std)
vAR_CSLAB_Z *= vAR_CSLAB_pred.min()
vAR_CSLAB_Z[idx[0], idx[1]] = vAR_CSLAB_pred
vAR_CSLAB_levels = vAR_np.linspace(vAR_CSLAB_Z.min(), vAR_CSLAB_Z.max(), 25)
vAR_CSLAB_Z[vAR_CSLAB_land_reference == -9999] = -9999
# plot contours of the prediction
vAR_plt.contourf(X, Y, vAR_CSLAB_Z, levels=vAR_CSLAB_levels, cmap=vAR_plt.cm.Reds)
vAR_plt.colorbar(format='%.2f')
# scatter training/testing points
vAR_plt.scatter(species.pts_train['dd long'], species.pts_train['dd lat'],
s=2 ** 2, c='black',
marker='^', label='train')
vAR_plt.scatter(species.pts_test['dd long'], species.pts_test['dd lat'],
s=2 ** 2, c='black',
marker='x', label='test')
vAR_plt.legend()
vAR_plt.title(species.name)
vAR_plt.axis('equal')
# Compute AUC with regards to background points
vAR_CSLAB_pred_background = vAR_CSLAB_Z[background_points[0], background_points[1]]
vAR_CSLAB_pred_test = vAR_CSLAB_clf.decision_function((species.cov_test - vAR_CSLAB_mean)
/ vAR_CSLAB_std)
vAR_CSLAB_scores = vAR_np.r_[vAR_CSLAB_pred_test, vAR_CSLAB_pred_background]
vAR_CSLAB_y = vAR_np.r_[vAR_np.ones(vAR_CSLAB_pred_test.shape), vAR_np.zeros(vAR_CSLAB_pred_background.shape)]
#fpr, tpr, thresholds = metrics.roc_curve(y, vAR_CSLAB_scores)
#roc_auc = metrics.auc(fpr, tpr)
#plt.text(-35, -70, "AUC: %.3f" % roc_auc, ha="right")
#print("\n Area under the ROC curve : %f" % roc_auc)
print("\ntime elapsed: %.2fs" % (time() - vAR_CSLAB_t0))
plot_species_distribution()
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_LASSO_REGRESSION_MODEL_V1
Purpose : A Program in Python for Lasso Regression Model Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 20:11 hrs
Version : 1.0
/******************************************
## Program Description : Program for Lasso Regression Model in Python
## Python Development Environment & Runtime - Python, Anaconda
from sklearn import linear_model
clf = linear_model.Lasso(alpha = 0.1)
clf.fit([[0, 0], [1, 1]], [0, 1])
Lasso(alpha=0.1, copy_X=True, fit_intercept=True, max_iter=1000,
normalize=False, positive=False, precompute=False, random_state=None,
selection='cyclic', tol=0.0001, warm_start=False)
clf.predict([[1, 1]])
array([ 0.8]
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_ISOTONIC_REGRESSION_SCIKIT_LEARN_V1
Purpose : A Program in Python for Isotonic Regression Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:51 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Isotonic Regression in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
import matplotlib.pyplot as vAR_plt
from matplotlib.collections import LineCollection
from sklearn.linear_model import LinearRegression
from sklearn.isotonic import IsotonicRegression
from sklearn.utils import check_random_state
vAR_CSLAB_n = 100
vAR_CSLAB_x = vAR_np.arange(vAR_CSLAB_n)
vAR_CSLAB_rs = check_random_state(0)
vAR_CSLAB_y = vAR_CSLAB_rs.randint(-50, 50, size=(vAR_CSLAB_n,)) + 50. * vAR_np.log(1 + vAR_np.arange(vAR_CSLAB_n))
# Fit IsotonicRegression and LinearRegression models
vAR_CSLAB_ir = IsotonicRegression()
vAR_CSLAB_y_ = vAR_CSLAB_ir.fit_transform(vAR_CSLAB_x, vAR_CSLAB_y)
vAR_CSLAB_lr = LinearRegression()
vAR_CSLAB_lr.fit(vAR_CSLAB_x[:, vAR_np.newaxis], vAR_CSLAB_y) # x needs to be 2d for LinearRegression
# plot result
vAR_CSLAB_segments = [[[i, vAR_CSLAB_y[i]], [i, vAR_CSLAB_y_[i]]] for i in range(vAR_CSLAB_n)]
vAR_CSLAB_lc = LineCollection(vAR_CSLAB_segments, zorder=0)
vAR_CSLAB_lc.set_array(vAR_np.ones(len(vAR_CSLAB_y)))
vAR_CSLAB_lc.set_linewidths(0.5 * vAR_np.ones(vAR_CSLAB_n))
vAR_CSLAB_fig = vAR_plt.figure()
vAR_plt.plot(vAR_CSLAB_x, vAR_CSLAB_y, 'r.', markersize=12)
vAR_plt.plot(vAR_CSLAB_x, vAR_CSLAB_y_, 'g.-', markersize=12)
vAR_plt.plot(vAR_CSLAB_x, vAR_CSLAB_lr.predict(vAR_CSLAB_x[:, vAR_np.newaxis]), 'b-')
vAR_plt.gca().add_collection(vAR_CSLAB_lc)
vAR_plt.legend(('Data', 'Isotonic Fit', 'Linear Fit'), loc='lower right')
vAR_plt.title('Isotonic regression')
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_NUERAL_NETWORKS_SCIKIT-LEARN_V1
Purpose : A Program in Python for Nueral Networks using SCIKIT-LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:52 hrs
Version : 1.0
/***********************************
## Program Description : Program for Nueral Networks in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import convolve
from sklearn import linear_model, datasets, metrics
from sklearn.cross_validation import train_test_split
from sklearn.neural_network import BernoulliRBM
from sklearn.pipeline import Pipeline
def nudge_dataset(X, Y):
shift = lambda x, w: convolve(x.reshape((8, 8)), mode='constant',
weights=w).ravel()
X = np.concatenate([X] +
[np.apply_along_axis(shift, 1, X, vector)
for vector in direction_vectors])
Y = np.concatenate([Y for _ in range(5)], axis=0)
return X, Y
digits = datasets.load_digits()
X = np.asarray(digits.data, 'float32')
X, Y = nudge_dataset(X, digits.target)
X = (X - np.min(X, 0)) / (np.max(X, 0) + 0.0001) # 0-1 scaling
X_train, X_test, Y_train, Y_test = train_test_split(X, Y,
test_size=0.2,
random_state=0)
logistic = linear_model.LogisticRegression()
rbm = BernoulliRBM(random_state=0, verbose=True)
classifier = Pipeline(steps=[('rbm', rbm), ('logistic', logistic)])
rbm.learning_rate = 0.06
rbm.n_iter = 20
rbm.n_components = 100
logistic.C = 6000.0
classifier.fit(X_train, Y_train)
logistic_classifier = linear_model.LogisticRegression(C=100.0)
logistic_classifier.fit(X_train, Y_train)
print()
print("Logistic regression using RBM features:n%sn" % (
metrics.classification_report(
Y_test,
classifier.predict(X_test))))
print("Logistic regression using raw pixel features:n%sn" % (
metrics.classification_report(
Y_test,
logistic_classifier.predict(X_test))))
plt.figure(figsize=(4.2, 4))
for i, comp in enumerate(rbm.components_):
plt.subplot(10, 10, i + 1)
plt.imshow(comp.reshape((8, 8)), cmap=plt.cm.gray_r,
interpolation='nearest')
plt.xticks(())
plt.yticks(())
plt.suptitle('100 components extracted by RBM', fontsize=16)
plt.subplots_adjust(0.08, 0.02, 0.92, 0.85, 0.08, 0.23)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_NON_LINEAR_SVM_SCIKIT-LEARN_V1
Purpose : A Program in Python for Non Linear SVM using SCIKIT-LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 16:22 hrs
Version : 1.0
/****************************************
## Program Description : Program for Non Linear SVM in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
import matplotlib.pyplot as vAR_plt
from sklearn import svm
vAR_CSLAB_xx, vAR_CSLAB_yy = vAR_np.meshgrid(vAR_np.linspace(-3, 3, 500),
vAR_np.linspace(-3, 3, 500))
vAR_np.random.seed(0)
vAR_CSLAB_X = vAR_np.random.randn(300, 2)
vAR_CSLAB_Y = vAR_np.logical_xor(vAR_CSLAB_X[:, 0] > 0, vAR_CSLAB_X[:, 1] > 0)
# fit the model
vAR_CSLAB_clf = svm.NuSVC()
vAR_CSLAB_clf.fit(vAR_CSLAB_X, vAR_CSLAB_Y)
# plot the decision function for each datapoint on the grid
vAR_CSLAB_Z = vAR_CSLAB_clf.decision_function(vAR_np.c_[vAR_CSLAB_xx.ravel(), vAR_CSLAB_yy.ravel()])
vAR_CSLAB_Z = vAR_CSLAB_Z.reshape(vAR_CSLAB_xx.shape)
vAR_plt.imshow(vAR_CSLAB_Z, interpolation='nearest',
extent=(vAR_CSLAB_xx.min(), vAR_CSLAB_xx.max(), vAR_CSLAB_yy.min(), vAR_CSLAB_yy.max()), aspect='auto',
origin='lower', cmap=vAR_plt.cm.PuOr_r)
vAR_CSLAB_contours = vAR_plt.contour(vAR_CSLAB_xx, vAR_CSLAB_yy, vAR_CSLAB_Z, levels=[0], linewidths=2,
linetypes='--')
vAR_plt.scatter(vAR_CSLAB_X[:, 0], vAR_CSLAB_X[:, 1], s=30, c=vAR_CSLAB_Y, cmap=vAR_plt.cm.Paired)
vAR_plt.xticks(())
vAR_plt.yticks(())
vAR_plt.axis([-3, 3, -3, 3])
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_DECISION_TREES_SCIKIT-LEARN_V1
Purpose : A Program in Python for Decision Trees using SCIKIT-LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 17:04 hrs
Version : 1.0
/****************************************
## Program Description : Program for Decision Trees in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
import matplotlib.pyplot as vAR_plt
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeRegressor
vAR_CSLAB_iris = load_iris()
# Create a random dataset
vAR_CSLAB_rng = vAR_np.random.RandomState(1)
vAR_CSLAB_X = vAR_np.sort(200 * vAR_CSLAB_rng.rand(100, 1) - 100, axis=0)
vAR_CSLAB_y = vAR_np.array([vAR_np.pi * vAR_np.sin(vAR_CSLAB_X).ravel(), vAR_np.pi * vAR_np.cos(vAR_CSLAB_X).ravel()]).T
#vAR_CSLAB_y[::5, :] += (0.5 - vAR_CSLAB_rng.rand(20, 2))
# Fit regression model
vAR_CSLAB_clf_1 = DecisionTreeRegressor(max_depth=2)
vAR_CSLAB_clf_2 = DecisionTreeRegressor(max_depth=5)
vAR_CSLAB_clf_3 = DecisionTreeRegressor(max_depth=8)
vAR_CSLAB_clf_1.fit(vAR_CSLAB_iris.data, vAR_CSLAB_iris.target)
vAR_CSLAB_clf_2.fit(vAR_CSLAB_iris.data, vAR_CSLAB_iris.target)
vAR_CSLAB_clf_3.fit(vAR_CSLAB_iris.data, vAR_CSLAB_iris.target)
# Predict
vAR_CSLAB_y_1 = vAR_CSLAB_clf_1.predict(vAR_CSLAB_iris.data[:50])
vAR_CSLAB_y_2 = vAR_CSLAB_clf_2.predict(vAR_CSLAB_iris.data[:50])
vAR_CSLAB_y_3 = vAR_CSLAB_clf_3.predict(vAR_CSLAB_iris.data[:50])
print(vAR_CSLAB_y_1)
print(vAR_CSLAB_y_2)
print(vAR_CSLAB_y_3)
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_PLOTTING_VALIDATION_CURVE_SCIKIT-LEARN_V1
Purpose : A Program in Python for Plotting Validation Curve using SCIKIT-LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:42 hrs
Version : 1.0
/****************************************
## Program Description : Program for Plotting Validation Curve in Python
## Python Development Environment & Runtime - Python, Anaconda
import matplotlib.pyplot as vAR_plt
import numpy as vAR_np
from sklearn.datasets import load_digits
from sklearn.svm import SVC
from sklearn.model_selection import validation_curve
vAR_CSLAB_digits = load_digits()
vAR_CSLAB_X, vAR_CSLAB_y = vAR_CSLAB_digits.data, vAR_CSLAB_digits.target
vAR_CSLAB_param_range = vAR_np.logspace(-6, -1, 5)
vAR_CSLAB_train_scores, vAR_CSLAB_test_scores = validation_curve(
SVC(), vAR_CSLAB_X, vAR_CSLAB_y, param_name="gamma", param_range=vAR_CSLAB_param_range,
cv=10, scoring="accuracy", n_jobs=1)
vAR_CSLAB_train_scores_mean = vAR_np.mean(vAR_CSLAB_train_scores, axis=1)
vAR_CSLAB_train_scores_std = vAR_np.std(vAR_CSLAB_train_scores, axis=1)
vAR_CSLAB_test_scores_mean = vAR_np.mean(vAR_CSLAB_test_scores, axis=1)
vAR_CSLAB_test_scores_std = vAR_np.std(vAR_CSLAB_test_scores, axis=1)
vAR_plt.title("Validation Curve with SVM")
vAR_plt.xlabel("$\gamma$")
vAR_plt.ylabel("Score")
vAR_plt.ylim(0.0, 1.1)
vAR_plt.semilogx(vAR_CSLAB_param_range, vAR_CSLAB_train_scores_mean, label="Training score", color="r")
vAR_plt.fill_between(vAR_CSLAB_param_range, vAR_CSLAB_train_scores_mean - vAR_CSLAB_train_scores_std,
vAR_CSLAB_train_scores_mean + vAR_CSLAB_train_scores_std, alpha=0.2, color="r")
vAR_plt.semilogx(vAR_CSLAB_param_range, vAR_CSLAB_test_scores_mean, label="Cross-validation score",
color="g")
vAR_plt.fill_between(vAR_CSLAB_param_range, vAR_CSLAB_test_scores_mean - vAR_CSLAB_test_scores_std,
vAR_CSLAB_test_scores_mean + vAR_CSLAB_test_scores_std, alpha=0.2, color="g")
vAR_plt.legend(loc="best")
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_LOADING_DATAETS_SCIKIT-LEARN_V1
Purpose : A Program in Python for Loading a Dataset using SCIKIT-LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:03 hrs
Version : 1.0
/***********************************
## Program Description : Program for Loading a Dataset in Python
## Python Development Environment & Runtime - Python, Anaconda
from sklearn import datasets
iris = datasets.load_iris()
digits = datasets.load_digits()
print(digits.data)
digits.target
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_MEAN_SHIFT_CLUSTERING_ALGORITHM_SCIKIT_LEARN_V1
Purpose : A Program in Python for Mean Shift Clustering Algorithm Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:41 hrs
Version : 1.0
/******************************************
## Program Description : Program for Mean Shift Clustering Algorithm in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
from sklearn.cluster import MeanShift, estimate_bandwidth
from sklearn.datasets.samples_generator import make_blobs
# Generate sample data
centers = [[1, 1], [-1, -1], [1, -1]]
X, _ = make_blobs(n_samples=10000, centers=centers, cluster_std=0.6)
# Compute clustering with MeanShift
# The following bandwidth can be automatically detected using
bandwidth = estimate_bandwidth(X, quantile=0.2, n_samples=500)
ms = MeanShift(bandwidth=bandwidth, bin_seeding=True)
ms.fit(X)
labels = ms.labels_
cluster_centers = ms.cluster_centers_
labels_unique = np.unique(labels)
n_clusters_ = len(labels_unique)
print("number of estimated clusters : %d" % n_clusters_)
# Plot result
import matplotlib.pyplot as plt
from itertools import cycle
plt.figure(1)
plt.clf()
colors = cycle('bgrcmykbgrcmykbgrcmykbgrcmyk')
for k, col in zip(range(n_clusters_), colors):
my_members = labels == k
cluster_center = cluster_centers[k]
plt.plot(X[my_members, 0], X[my_members, 1], col + '.')
plt.plot(cluster_center[0], cluster_center[1], 'o', markerfacecolor=col,
markeredgecolor='k', markersize=14)
plt.title('Estimated number of clusters: %d' % n_clusters_)
plt.show()
/************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_AFFINITY_PROPOGATION_CLUSTERING_ALGORITHM_SCIKIT_LEARN_V1
Purpose : A Program in Python for Affinity Propogation Clustering Algorithm Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:41 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Affinity Propogation Clustering Algorithm in Python
## Python Development Environment & Runtime - Python, Anaconda
from sklearn.cluster import AffinityPropagation
from sklearn import metrics
from sklearn.datasets.samples_generator import make_blobs
vAR_CSLAB_centers = [[1, 1], [-1, -1], [1, -1]]
vAR_CSLAB_X, vAR_CSLAB_labels_true = make_blobs(n_samples=300, centers=vAR_CSLAB_centers, cluster_std=0.5,
random_state=0)
vAR_CSLAB_af = AffinityPropagation(preference=-50).fit(vAR_CSLAB_X)
vAR_CSLAB_cluster_centers_indices = vAR_CSLAB_af.cluster_centers_indices_
vAR_CSLAB_labels = vAR_CSLAB_af.labels_
vAR_CSLAB_n_clusters_ = len(vAR_CSLAB_cluster_centers_indices)
print('Estimated number of clusters: %d' % vAR_CSLAB_n_clusters_)
print("Homogeneity: %0.3f" % metrics.homogeneity_score(vAR_CSLAB_labels_true, vAR_CSLAB_labels))
print("Completeness: %0.3f" % metrics.completeness_score(vAR_CSLAB_labels_true, vAR_CSLAB_labels))
print("V-measure: %0.3f" % metrics.v_measure_score(vAR_CSLAB_labels_true, vAR_CSLAB_labels))
print("Adjusted Rand Index: %0.3f"
% metrics.adjusted_rand_score(vAR_CSLAB_labels_true, vAR_CSLAB_labels))
print("Adjusted Mutual Information: %0.3f"
% metrics.adjusted_mutual_info_score(vAR_CSLAB_labels_true, vAR_CSLAB_labels))
print("Silhouette Coefficient: %0.3f"
% metrics.silhouette_score(vAR_CSLAB_X, vAR_CSLAB_labels, metric='sqeuclidean'))
# Plot result
import matplotlib.pyplot as vAR_plt
from itertools import cycle
vAR_plt.close('all')
vAR_plt.figure(1)
vAR_plt.clf()
vAR_colors = cycle('bgrcmykbgrcmykbgrcmykbgrcmyk')
for vAR_CSLAB_k, col in zip(range(vAR_CSLAB_n_clusters_), vAR_colors):
vAR_CSLAB_class_members = vAR_CSLAB_labels == vAR_CSLAB_k
vAR_CSLAB_cluster_center = vAR_CSLAB_X[vAR_CSLAB_cluster_centers_indices[vAR_CSLAB_k]]
vAR_plt.plot(vAR_CSLAB_X[vAR_CSLAB_class_members, 0], vAR_CSLAB_X[vAR_CSLAB_class_members, 1], col + '.')
vAR_plt.plot(vAR_CSLAB_cluster_center[0], vAR_CSLAB_cluster_center[1], 'o', markerfacecolor=col,
markeredgecolor='k', markersize=14)
for x in vAR_CSLAB_X[vAR_CSLAB_class_members]:
vAR_plt.plot([vAR_CSLAB_cluster_center[0], vAR_CSLAB_x[0]], [vAR_CSLAB_cluster_center[1], vAR_CSLAB_x[1]], col)
vAR_plt.title('Estimated number of clusters: %d' % vAR_CSLAB_n_clusters_)
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_DBSCAN_CLUSTERING_ALGORITHM_SCIKIT_LEARN_V1
Purpose : A Program in Python for DBSCAN Clustering Algorithm Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 16:05 hrs
Version : 1.0
/***********************************************
## Program Description : Program for DBSCAN Clustering Algorithm in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
from sklearn.cluster import DBSCAN
from sklearn import metrics
from sklearn.datasets.samples_generator import make_blobs
from sklearn.preprocessing import StandardScaler
# Generate sample data
vAR_CSLAB_centers = [[1, 1], [-1, -1], [1, -1]]
vAR_CSLAB_X, vAR_CSLAB_labels_true = make_blobs(n_samples=750, centers=vAR_CSLAB_centers, cluster_std=0.4,
random_state=0)
vAR_CSLAB_X = StandardScaler().fit_transform(vAR_CSLAB_X)
# Compute DBSCAN
vAR_CSLAB_db = DBSCAN(eps=0.3, min_samples=10).fit(vAR_CSLAB_X)
vAR_CSLAB_core_samples_mask = vAR_np.zeros_like(vAR_CSLAB_db.labels_, dtype=bool)
vAR_CSLAB_core_samples_mask[vAR_CSLAB_db.core_sample_indices_] = True
vAR_CSLAB_labels = vAR_CSLAB_db.labels_
# Number of clusters in labels, ignoring noise if present.
vAR_CSLAB_n_clusters_ = len(set(vAR_CSLAB_labels)) - (1 if -1 in vAR_CSLAB_labels else 0)
print('Estimated number of clusters: %d' % vAR_CSLAB_n_clusters_)
print("Homogeneity: %0.3f" % metrics.homogeneity_score(vAR_CSLAB_labels_true, vAR_CSLAB_labels))
print("Completeness: %0.3f" % metrics.completeness_score(vAR_CSLAB_labels_true, vAR_CSLAB_labels))
print("V-measure: %0.3f" % metrics.v_measure_score(vAR_CSLAB_labels_true, vAR_CSLAB_labels))
print("Adjusted Rand Index: %0.3f"
% metrics.adjusted_rand_score(vAR_CSLAB_labels_true, vAR_CSLAB_labels))
print("Adjusted Mutual Information: %0.3f"
% metrics.adjusted_mutual_info_score(vAR_CSLAB_labels_true, vAR_CSLAB_labels))
print("Silhouette Coefficient: %0.3f"
% metrics.silhouette_score(vAR_CSLAB_X, vAR_CSLAB_labels))
# Plot result
import matplotlib.pyplot as vAR_plt
# Black removed and is used for noise instead.
vAR_CSLAB_unique_labels = set(vAR_CSLAB_labels)
vAR_CSLAB_colors = vAR_plt.cm.Spectral(vAR_np.linspace(0, 1, len(vAR_CSLAB_unique_labels)))
for k, col in zip(vAR_CSLAB_unique_labels, vAR_CSLAB_colors):
if k == -1:
vAR_CSLAB_col = 'k'
vAR_CSLAB_class_member_mask = (vAR_CSLAB_labels == vAR_CSLAB_k)
vAR_CSLAB_xy = vAR_CSLAB_X[vAR_CSLAB_class_member_mask & vAR_CSLAB_core_samples_mask]
vAR_plt.plot(vAR_CSLAB_xy[:, 0], vAR_CSLAB_xy[:, 1], 'o', markerfacecolor=col,
markeredgecolor='k', markersize=14)
vAR_CSLAB_xy = vAR_CSLAB_X[vAR_CSLAB_class_member_mask & ~vAR_CSLAB_core_samples_mask]
vAR_plt.plot(vAR_CSLAB_xy[:, 0], vAR_CSLAB_xy[:, 1], 'o', markerfacecolor=col,
markeredgecolor='k', markersize=6)
vAR_plt.title('Estimated number of clusters: %d' % vAR_CSLAB_n_clusters_)
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_KMEANS_CLUSTERING_ALGORITHM_SCIKIT_LEARN_V1
Purpose : A Program in Python for KMEANS Clustering Algorithm Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 16:41 hrs
Version : 1.0
/***********************************************
## Program Description : Program for KMEANS Clustering Algorithm in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
import matplotlib.pyplot as vAR_plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.cluster import KMeans
from sklearn import datasets
vAR_np.random.seed(5)
vAR_CSLAB_centers = [[1, 1], [-1, -1], [1, -1]]
vAR_CSLAB_iris = datasets.load_iris()
vAR_CSLAB_X = vAR_CSLAB_iris.data
vAR_CSLAB_y = vAR_CSLAB_iris.target
vAR_CSLAB_estimators = {'k_means_iris_3': KMeans(n_clusters=3),
'k_means_iris_8': KMeans(n_clusters=8),
'k_means_iris_bad_init': KMeans(n_clusters=3, n_init=1,
init='random')}
vAR_CSLAB_fignum = 1
for name, est in vAR_CSLAB_estimators.items():
vAR_CSLAB_fig = vAR_plt.figure(vAR_CSLAB_fignum, figsize=(4, 3))
vAR_plt.clf()
vAR_CSLAB_ax = Axes3D(vAR_CSLAB_fig, rect=[0, 0, .95, 1], elev=48, azim=134)
vAR_plt.cla()
est.fit(vAR_CSLAB_X)
vAR_CSLAB_labels = est.labels_
vAR_CSLAB_ax.scatter(vAR_CSLAB_X[:, 3], vAR_CSLAB_X[:, 0], vAR_CSLAB_X[:, 2], c=vAR_CSLAB_labels.astype(vAR_np.float))
vAR_CSLAB_ax.w_xaxis.set_ticklabels([])
vAR_CSLAB_ax.w_yaxis.set_ticklabels([])
vAR_CSLAB_ax.w_zaxis.set_ticklabels([])
vAR_CSLAB_ax.set_xlabel('Petal width')
vAR_CSLAB_ax.set_ylabel('Sepal length')
vAR_CSLAB_ax.set_zlabel('Petal length')
vAR_CSLAB_fignum = vAR_CSLAB_fignum + 1
# Plot the ground truth
vAR_CSLAB_fig = vAR_plt.figure(vAR_CSLAB_fignum, figsize=(4, 3))
vAR_plt.clf()
vAR_CSLAB_ax = Axes3D(vAR_CSLAB_fig, rect=[0, 0, .95, 1], elev=48, azim=134)
vAR_plt.cla()
for name, label in [('Setosa', 0),
('Versicolour', 1),
('Virginica', 2)]:
vAR_CSLAB_ax.text3D(vAR_CSLAB_X[vAR_CSLAB_y == label, 3].mean(),
vAR_CSLAB_X[vAR_CSLAB_y == label, 0].mean() + 1.5,
vAR_CSLAB_X[vAR_CSLAB_y == label, 2].mean(), name,
horizontalalignment='center',
bbox=dict(alpha=.5, edgecolor='w', facecolor='w'))
# Reorder the labels to have colors matching the cluster results
vAR_CSLAB_y = vAR_np.choose(vAR_CSLAB_y, [1, 2, 0]).astype(vAR_np.float)
vAR_CSLAB_ax.scatter(vAR_CSLAB_X[:, 3], vAR_CSLAB_X[:, 0], vAR_CSLAB_X[:, 2], c=vAR_CSLAB_y)
vAR_CSLAB_ax.w_xaxis.set_ticklabels([])
vAR_CSLAB_ax.w_yaxis.set_ticklabels([])
vAR_CSLAB_ax.w_zaxis.set_ticklabels([])
vAR_CSLAB_ax.set_xlabel('Petal width')
vAR_CSLAB_ax.set_ylabel('Sepal length')
vAR_CSLAB_ax.set_zlabel('Petal length')
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_SPECTRAL_BI-CLUSTERING_ALGORITHM_SCIKIT_LEARN_V1
Purpose : A Program in Python for Spectral Bi-Clustering Algorithm Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 17:38 hrs
Version : 1.0
/******************************************
## Program Description : Program for Spectral Bi-Clustering Algorithm in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
from matplotlib import pyplot as plt
from sklearn.datasets import make_checkerboard
from sklearn.datasets import samples_generator as sg
from sklearn.cluster.bicluster import SpectralBiclustering
from sklearn.metrics import consensus_score
n_clusters = (4, 3)
data, rows, columns = make_checkerboard(
shape=(300, 300), n_clusters=n_clusters, noise=10,
shuffle=False, random_state=0)
plt.matshow(data, cmap=plt.cm.Blues)
plt.title("Original dataset")
data, row_idx, col_idx = sg._shuffle(data, random_state=0)
plt.matshow(data, cmap=plt.cm.Blues)
plt.title("Shuffled dataset")
model = SpectralBiclustering(n_clusters=n_clusters, method='log',
random_state=0)
model.fit(data)
score = consensus_score(model.biclusters_,
(rows[:, row_idx], columns[:, col_idx]))
print("consensus score: {:.1f}".format(score))
fit_data = data[np.argsort(model.row_labels_)]
fit_data = fit_data[:, np.argsort(model.column_labels_)]
plt.matshow(fit_data, cmap=plt.cm.Blues)
plt.title("After biclustering; rearranged to show biclusters")
plt.matshow(np.outer(np.sort(model.row_labels_) + 1,
np.sort(model.column_labels_) + 1),
cmap=plt.cm.Blues)
plt.title("Checkerboard structure of rearranged data")
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SPECTRAL_CO-CLUSTERING_ALGORITHM_SCIKIT_LEARN_V1
Purpose : A Program in Python for Spectral Co-Clustering Algorithm Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 17:13 hrs
Version : 1.0
/******************************************
## Program Description : Program for Spectral Co-Clustering Algorithm in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
from matplotlib import pyplot as plt
from sklearn.datasets import make_biclusters
from sklearn.datasets import samples_generator as sg
from sklearn.cluster.bicluster import SpectralCoclustering
from sklearn.metrics import consensus_score
data, rows, columns = make_biclusters(
shape=(300, 300), n_clusters=5, noise=5,
shuffle=False, random_state=0)
plt.matshow(data, cmap=plt.cm.Blues)
plt.title("Original dataset")
data, row_idx, col_idx = sg._shuffle(data, random_state=0)
plt.matshow(data, cmap=plt.cm.Blues)
plt.title("Shuffled dataset")
model = SpectralCoclustering(n_clusters=5, random_state=0)
model.fit(data)
score = consensus_score(model.biclusters_,
(rows[:, row_idx], columns[:, col_idx]))
print("consensus score: {:.3f}".format(score))
fit_data = data[np.argsort(model.row_labels_)]
fit_data = fit_data[:, np.argsort(model.column_labels_)]
plt.matshow(fit_data, cmap=plt.cm.Blues)
plt.title("After biclustering; rearranged to show biclusters")
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_RIDGE_REGRESSION_SCIKIT_LEARN_V1
Purpose : A Program in Python for Ridge Regression Algorithm Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 17:49 hrs
Version : 1.0
/******************************************
## Program Description : Program for Ridge Regression Algorithm in Python
## Python Development Environment & Runtime - Python, Anaconda
from sklearn import linear_model
clf = linear_model.Ridge (alpha = .5)
clf.fit ([[0, 0], [0, 0], [1, 1]], [0, .1, 1])
Ridge(alpha=0.5, copy_X=True, fit_intercept=True, max_iter=None,
normalize=False, random_state=None, solver='auto', tol=0.001)
clf.coef_
array([ 0.34545455, 0.34545455])
clf.intercept_
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SCIENTIFIC_ANALYSIS_ARRAYS_NUMPY_V1
Purpose : A Program in Python for Arrays using Numpy
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 11:12 hrs
Version : 1.0
/******************************************
## Program Description : Program for Arrays using Numpy in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
CSLAB_X = np.array([42,47,11], int)
CSLAB_X
CSLAB_X = np.array( ((11,12,13), (21,22,23), (31,32,33)) )
print CSLAB_X
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SCIENTIFIC_ANALYSIS_ARRAYS_RESHAPING_NUMPY_V1
Purpose : A Program in Python for Reshaping Arrays using Numpy
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 11:47 hrs
Version : 1.0
/******************************************
## Program Description : Program for Reshaping Arrays using Numpy in Python
## Python Development Environment & Runtime - Python, Anaconda
CSLAB_X = np.array([[[ 0, 1],
[ 2, 3],
[ 4, 5],
[ 6, 7]],
[[ 8, 9],
[10, 11],
[12, 13],
[14, 15]],
[[16, 17],
[18, 19],
[20, 21],
[22, 23]]])
CSLAB_X.flatten()
CSLAB_X
CSLAB_X.ravel()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SCIENTIFIC_ANALYSIS_ARRAYS_CONCATENATING_NUMPY_V1
Purpose : A Program in Python for Concatenating Arrays using Numpy
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:14 hrs
Version : 1.0
/******************************************
## Program Description : Program for Concatenating Arrays using Numpy in Python
## Python Development Environment & Runtime - Python, Anaconda
CSLAB_X = np.array([11,22])
CSLAB_Y = np.array([18,7,6])
CSLAB_Z = np.array([1,3,5])
np.concatenate((CSLAB_X,CSLAB_Y,CSLAB_Z))
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SCIENTIFIC_ANALYSIS_ARRAYS_ADDING_NEW_DIMENSIONS_NUMPY_V1
Purpose : A Program in Python for Adding New Dimensions to Arrays using Numpy
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:41 hrs
Version : 1.0
/******************************************
## Program Description : Program for Adding New Dimensions to Arrays using Numpy in Python
## Python Development Environment & Runtime - Python, Anaconda
CSLAB_X = np.array([2,5,18,14,4])
CSLAB_X
CSLAB_Y = CSLAB_X[:, np.newaxis]
CSLAB_Y
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SCIENTIFIC_ANALYSIS_ARRAYS_INITIALIZING_WITH_ZEROS_ONES_NUMPY_V1
Purpose : A Program in Python for Initializing With Zero's & One's to Arrays using Numpy
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:41 hrs
Version : 1.0
/******************************************
## Program Description : Program for Initializing With Zero's & One's to Arrays using Numpy in Python
## Python Development Environment & Runtime - Python, Anaconda
np.ones((2,3))
np.ones((3,4),dtype=int)
np.zeros((2,4))
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SCIENTIFIC_ANALYSIS_MGRID_SCIPY_V1
Purpose : A Program in Python for Mgrid Function in scipy
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 13:17 hrs
Version : 1.0
/******************************************
## Program Description : Program for Mgrid Function in scipy in Python
## Python Development Environment & Runtime - Python, Anaconda
from scipy import *
mgrid[0:5,0:5]
mgrid[0:5:4j,0:5:4j]
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SCIENTIFIC_ANALYSIS_POLYNOMIAL_SCIPY_V1
Purpose : A Program in Python for Polynomials in scipy
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 13:17 hrs
Version : 1.0
/******************************************
## Program Description : Program for Polynomials in scipy in Python
## Python Development Environment & Runtime - Python, Anaconda
from scipy import *
CSLAB_P = poly1d([3,4,5])
print CSLAB_P
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SCIENTIFIC_ANALYSIS_VECTORIZING_FUNCTIONS_SCIPY_V1
Purpose : A Program in Python for Vectorizing Functions in scipy
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:00 hrs
Version : 1.0
/******************************************
## Program Description : Program for Vectorizing Functions in scipy in Python
## Python Development Environment & Runtime - Python, Anaconda
from scipy import *
def addsubtract(CSLAB_A,CSLAB_B):
if CSLAB_A > CSLAB_B:
return CSLAB_A - CSLAB_B
else:
return CSLAB_A + CSLAB_B
vec_addsubtract = vectorize(addsubtract)
vec_addsubtract([0,3,6,9],[1,3,5,7])
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SCIENTIFIC_ANALYSIS_SELECT_FUNCTION_SCIPY_V1
Purpose : A Program in Python for Select Functions in scipy
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:27 hrs
Version : 1.0
/******************************************
## Program Description : Program for Select Functions in scipy in Python
## Python Development Environment & Runtime - Python, Anaconda
from scipy import *
CSLAB_X = r_[-2:3]
CSLAB_X
select([(CSLAB_X) > 3, (CSLAB_X) >= 0],[0,(CSLAB_X)+2])
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SCIENTIFIC_ANALYSIS_GENERAL_INTEGRATION_SCIPY_V1
Purpose : A Program in Python for General Integration in scipy
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:45 hrs
Version : 1.0
/******************************************
## Program Description : Program for General Integration in scipy in Python
## Python Development Environment & Runtime - Python, Anaconda
from scipy import *
result = integrate.quad(lambda x: special.jv(2.5,x), 0, 4.5)
print result
CSLAB_I = sqrt(2/pi)*(18.0/27*sqrt(2)*cos(4.5)-4.0/27*sqrt(2)*sin(4.5) + sqrt(2*pi)*special.fresnl(3/sqrt(pi))[0])
print CSLAB_I
print abs(result[0]-CSLAB_I)
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_TIME_SERIES_ANALYSIS_PANDAS_V1
Purpose : A Program in Python for Time Series Analysis Using Pandas
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:47 hrs
Version : 1.0
/******************************************
## Program Description : Program for Time Series Analysis Using Pandas in Python
## Python Development Environment & Runtime - Python, Anaconda
% matplotlib inline
import matplotlib.pyplot as plt
import datetime
import pandas as pd
yhoo = DataReader("yhoo", "yahoo", datetime.datetime(2007, 1, 1),
datetime.datetime(2012,1,1))
top = plt.subplot2grid((4,4), (0, 0), rowspan=3, colspan=4)
top.plot(yhoo.index, yhoo["Close"])
plt.title('Yahoo Price from 2007 - 2012')
bottom = plt.subplot2grid((4,4), (3,0), rowspan=1, colspan=4)
bottom.bar(yhoo.index, yhoo['Volume'])
plt.title('Yahoo Trading Volume')
plt.gcf().set_size_inches(15,8)
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_EXPORTING_DATA_USING_PANDAS_V1
Purpose : A Program in Python for EXporting Data Using Pandas
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 18:37 hrs
Version : 1.0
/******************************************
## Program Description : Program for EXporting Data Using Pandas in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as pd
s = pd.Series([1,3,5,np.nan,6,8])
pd.DataFrame(s).to_excel('E:/Python/s.xlsx', 's')
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_IMPORTING_DATA_USING_PANDAS_V1
Purpose : A Program in Python for Importing Data Using Pandas
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 18:15 hrs
Version : 1.0
/******************************************
## Program Description : Program for Importing Data Using Pandas in Python
## Python Development Environment & Runtime - Python, Anaconda
from pandas import read_csv
from urllib import urlopen
page = urlopen("http://econpy.pythonanywhere.com/ex/NFL_1979.csv")
df = read_csv(page)
print df
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/*******************
File Name : CSLAB_DATA_ANALYSIS_PANDAS_V1
Purpose : A Program in Python for Data Analysis
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 10:52 hrs
Version : 1.0
/*******************
## Program Description : Program for Data Analysis in Python
## Python Development Environment & Runtime - Python, Anaconda
import os
vAR_INI_File_Path = os.environ.get('PYTHON_TUTORIAL')
import pandas as vAR_pd
import configparser
import matplotlib as vAR_plt
vAR_Config = configparser.ConfigParser(allow_no_value=True)
vAR_Config.read(vAR_INI_File_Path)
vAR_CSLAB_Customer = vAR_Config['Data File Path']['vAR_CSLAB_PROGRAM_106_CUSTOMER']
vAR_CSLAB_Customer = vAR_pd.read_excel(vAR_CSLAB_Customer)
vAR_CSLAB_Customer
vAR_CSLAB_FIGURE = vAR_plt.pyplot.figure()
vAR_CSLAB_FIGURE = vAR_plt.pyplot.figure()
vAR_CSLAB_AX = vAR_CSLAB_FIGURE.add_subplot(111)
vAR_CSLAB_AX.hist(vAR_CSLAB_Customer['Customer_ID'], bins = 10, range = (vAR_CSLAB_Customer['Customer_ID'].min(),vAR_CSLAB_Customer['Customer_ID'].max()))
/*******************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************
/************************************
File Name : CSLAB_EMPTY_GRAPH_NETWORKX_V1
Purpose : A Program in Python for Drawing Empty Graph With NetworkX Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:05 hrs
Version : 1.0
/***********************************
## Program Description : Program for Drawing Empty Graph With NetworkX Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import networkx as nx
CSLAB_G=nx.Graph()
print(CSLAB_G.nodes())
print(CSLAB_G.edges())
print(type(CSLAB_G.nodes()))
print(type(CSLAB_G.edges()))
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPH_ADDING_NODES_NETWORKX_V1
Purpose : A Program in Python for Adding Nodes to a Graph With NetworkX Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:29 hrs
Version : 1.0
/***********************************
## Program Description : Program for Adding Nodes to a Graph With NetworkX Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import networkx as nx
CSLAB_G=nx.Graph()
# adding just one node:
CSLAB_G.add_node("a")
# a list of nodes:
CSLAB_G.add_nodes_from(["b","c"])
print("Nodes of graph: ")
print(CSLAB_G.nodes())
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_GRAPH_ADDING_EDGES_NETWORKX_V1
Purpose : A Program in Python for Adding Edges to a Graph With NetworkX Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:54 hrs
Version : 1.0
/****************************************
## Program Description : Program for Adding Edges to a Graph With NetworkX Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import networkx as vAR_nx
vAR_CSLAB_G=vAR_nx.Graph()
vAR_CSLAB_G.add_node("a")
vAR_CSLAB_G.add_nodes_from(["b","c"])
vAR_CSLAB_G.add_edge(1,2)
vAR_edge = ("d", "e")
vAR_CSLAB_G.add_edge(*vAR_edge)
vAR_edge = ("a", "b")
vAR_CSLAB_G.add_edge(*vAR_edge)
print("Nodes of graph: ")
print(vAR_CSLAB_G.nodes())
print("Edges of graph: ")
print(vAR_CSLAB_G.edges())
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_GRAPH_DISPLAY_NETWORKX_V1
Purpose : A Program in Python for the Graph With Nodes & Edges using NetworkX Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 13:22 hrs
Version : 1.0
/******************************************
## Program Description : Program for the Graph With Nodes & Edges using NetworkX Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import networkx as nx
CSLAB_G=nx.Graph()
CSLAB_G.add_node("a")
CSLAB_G.add_nodes_from(["b","c"])
CSLAB_G.add_edge(1,2)
edge = ("d", "e")
CSLAB_G.add_edge(*edge)
edge = ("a", "b")
CSLAB_G.add_edge(*edge)
print("Nodes of graph: ")
print(CSLAB_G.nodes())
print("Edges of graph: ")
print(CSLAB_G.edges())
CSLAB_G.add_edges_from([("a","c"),("c","d"), ("a",1), (1,"d"), ("a",2)])
nx.draw(CSLAB_G)
plt.show() # display
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPH_PATH_NETWORKX_V1
Purpose : A Program in Python for Path Graph using NetworkX Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 13:51 hrs
Version : 1.0
/***********************************
## Program Description : Program for Path Graph using NetworkX Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import networkx as nx
import matplotlib.pyplot as plt
CSLAB_G=nx.path_graph(4)
print("Nodes of graph: ")
print(CSLAB_G.nodes())
print("Edges of graph: ")
print(CSLAB_G.edges())
nx.draw(CSLAB_G)
plt.savefig("path_graph1.png")
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_RENAMING_NODES_NETWORKX_V1
Purpose : A Program in Python for Renaming Nodes of a Graph using NetworkX Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:42 hrs
Version : 1.0
/****************************************
## Program Description : Program for Renaming Nodes a Graph using NetworkX Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import os
vAR_INI_File_Path = os.environ.get('PYTHON_TUTORIAL')
import pandas as vAR_pd
import configparser
import matplotlib.pyplot as vAR_plt
vAR_Config = configparser.ConfigParser(allow_no_value=True)
vAR_Config.read(vAR_INI_File_Path)
vAR_CSLAB_Save_Graph = vAR_Config['Data File Path']['vAR_CSLAB_PROGRAM_112_SAVE_GRAPH']
import networkx as vAR_nx
import matplotlib.pyplot as vAR_plt
vAR_CSLAB_G=vAR_nx.path_graph(4)
vAR_cities = {0:"Toronto",1:"London",2:"Berlin",3:"New York"}
vAR_CSLAB_H=vAR_nx.relabel_nodes(vAR_CSLAB_G,vAR_cities)
print("Nodes of graph: ")
print(vAR_CSLAB_H.nodes())
print("Edges of graph: ")
print(vAR_CSLAB_H.edges())
vAR_nx.draw(vAR_CSLAB_H)
vAR_plt.savefig(vAR_CSLAB_Save_Graph)
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_EXAMPLE_PYMC_V1
Purpose : A Program in Python PYMC Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:31 hrs
Version : 1.0
/****************************************
## Program Description : Program for PYMC Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
import matplotlib.pyplot as vAR_plt
vAR_plt.style.use('seaborn-darkgrid')
# Initialize random number generator
vAR_np.random.seed(123)
# True parameter values
vAR_CSLAB_alpha, vAR_CSLAB_sigma = 1, 1
vAR_CSLAB_beta = [1, 2.5]
# Size of dataset
vAR_CSLAB_size = 100
# Predictor variable
vAR_CSLAB_X1 = vAR_np.random.randn(vAR_CSLAB_size)
vAR_CSLAB_X2 = vAR_np.random.randn(vAR_CSLAB_size) * 0.2
# Simulate outcome variable
vAR_CSLAB_Y = vAR_CSLAB_alpha + vAR_CSLAB_beta[0]*vAR_CSLAB_X1 + vAR_CSLAB_beta[1]*vAR_CSLAB_X2 + vAR_np.random.randn(vAR_CSLAB_size)*vAR_CSLAB_sigma
%matplotlib inline
fig, axes = vAR_plt.subplots(1, 2, sharex=True, figsize=(10,4))
axes[0].scatter(vAR_CSLAB_X1, vAR_CSLAB_Y)
axes[1].scatter(vAR_CSLAB_X2, vAR_CSLAB_Y)
axes[0].set_ylabel('Y'); axes[0].set_xlabel('vAR_CSLAB_X1'); axes[1].set_xlabel('vAR_CSLAB_X2');
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_L1_BASED_FEATURE_SELECTION_V1
Purpose : A Program in Python for L1 Based Feature Selection
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 18:07 hrs
Version : 1.0
/***********************************************
## Program Description : Program for L1 Based Feature Selection in Python
## Python Development Environment & Runtime - Python, Anaconda
from sklearn.svm import LinearSVC
from sklearn.datasets import load_iris
from sklearn.feature_selection import SelectFromModel
vAR_CSLAB_iris = load_iris()
vAR_CSLAB_X, vAR_CSLAB_y = vAR_CSLAB_iris.data, vAR_CSLAB_iris.target
vAR_CSLAB_X.shape
vAR_CSLAB_lsvc = LinearSVC(C=0.01, penalty="l1", dual=False).fit(vAR_CSLAB_X, vAR_CSLAB_y)
vAR_CSLAB_model = SelectFromModel(vAR_CSLAB_lsvc, prefit=True)
vAR_CSLAB_X_new = vAR_CSLAB_model.transform(vAR_CSLAB_X)
vAR_CSLAB_X_new.shape
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_LINE_PLOT_MATPLOTLIB_V1
Purpose : A Program in Python for Line Plot using Matplotlib Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 10:15 hrs
Version : 1.0
/******************************************
## Program Description : Program for Line Plot using Matplotlib Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('Numbers')
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_DOT_PLOT_MATPLOTLIB_V1
Purpose : A Program in Python for Dot Plot using Matplotlib Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 10:31 hrs
Version : 1.0
/******************************************
## Program Description : Program for Dot Plot using Matplotlib Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'bo')
plt.axis([0, 6, 0, 20])
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_NUMERIC_PLOT_MATPLOTLIB_V1
Purpose : A Program in Python for Numeric Plot using Matplotlib Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 11:04 hrs
Version : 1.0
/******************************************
## Program Description : Program for Numeric Plot using Matplotlib Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
import matplotlib.pyplot as plt
# evenly sampled time at 200ms intervals
t = np.arange(0., 5., 0.2)
# red dashes, blue squares and green triangles
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_FIGURES_AXES_MATPLOTLIB_V1
Purpose : A Program in Python for Figures & Axes using Matplotlib Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 11:54 hrs
Version : 1.0
/******************************************
## Program Description : Program for Figures & Axes using Matplotlib Package in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
import matplotlib.pyplot as plt
def f(t):
return np.exp(-t) * np.cos(2*np.pi*t)
t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)
plt.figure(1)
plt.subplot(211)
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')
plt.subplot(212)
plt.plot(t2, np.cos(2*np.pi*t2), 'r--')
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_2D_PLOTTING_MAPPLOTLIB_V1
Purpose : A Program in Python for 2D Plotting using Matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:09 hrs
Version : 1.0
/******************************************
## Program Description : Program for 2D Plotting using Matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
x = np.linspace(0, 1, 100)
y = np.sin(x * 2 * np.pi) / 2 + 0.5
ax.plot(x, y, zs=0, zdir='z', label='zs=0, zdir=z')
colors = ('r', 'g', 'b', 'k')
for c in colors:
x = np.random.sample(20)
y = np.random.sample(20)
ax.scatter(x, y, 0, zdir='y', c=c)
ax.legend()
ax.set_xlim3d(0, 1)
ax.set_ylim3d(0, 1)
ax.set_zlim3d(0, 1)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_2D_PLOT_SCIKIT_LEARN_V1
Purpose : A Program in Python for 2D Plotting Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:45 hrs
Version : 1.0
## Program Description : Program for 2D Plotting Using SCIKIT LEARN in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
x = np.linspace(0, 1, 100)
y = np.sin(x * 2 * np.pi) / 2 + 0.5
ax.plot(x, y, zs=0, zdir='z', label='zs=0, zdir=z')
colors = ('r', 'g', 'b', 'k')
for c in colors:
x = np.random.sample(20)
y = np.random.sample(20)
ax.scatter(x, y, 0, zdir='y', c=c)
ax.legend()
ax.set_xlim3d(0, 1)
ax.set_ylim3d(0, 1)
ax.set_zlim3d(0, 1)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_CLASSIFICATION_SCIKIT_LEARN_V1
Purpose : A Program in Python for Classification Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 16:38 hrs
Version : 1.0
/******************************************
## Program Description : Program for Classification Using SCIKIT LEARN in Python
## Python Development Environment & Runtime - Python, Anaconda
from scipy import linalg
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from matplotlib import colors
from sklearn.lda import LDA
from sklearn.qda import QDA
cmap = colors.LinearSegmentedColormap(
'red_blue_classes',
{'red': [(0, 1, 1), (1, 0.7, 0.7)],
'green': [(0, 0.7, 0.7), (1, 0.7, 0.7)],
'blue': [(0, 0.7, 0.7), (1, 1, 1)]})
plt.cm.register_cmap(cmap=cmap)
def dataset_fixed_cov():
'''Generate 2 Gaussians samples with the same covariance matrix'''
n, dim = 300, 2
np.random.seed(0)
C = np.array([[0., -0.23], [0.83, .23]])
X = np.r_[np.dot(np.random.randn(n, dim), C),
np.dot(np.random.randn(n, dim), C) + np.array([1, 1])]
y = np.hstack((np.zeros(n), np.ones(n)))
return X, y
def dataset_cov():
'''Generate 2 Gaussians samples with different covariance matrices'''
n, dim = 300, 2
np.random.seed(0)
C = np.array([[0., -1.], [2.5, .7]]) * 2.
X = np.r_[np.dot(np.random.randn(n, dim), C),
np.dot(np.random.randn(n, dim), C.T) + np.array([1, 4])]
y = np.hstack((np.zeros(n), np.ones(n)))
return X, y
def plot_data(lda, X, y, y_pred, fig_index):
splot = plt.subplot(2, 2, fig_index)
if fig_index == 1:
plt.title('Linear Discriminant Analysis')
plt.ylabel('Data with fixed covariance')
elif fig_index == 2:
plt.title('Quadratic Discriminant Analysis')
elif fig_index == 3:
plt.ylabel('Data with varying covariances')
tp = (y == y_pred) # True Positive
tp0, tp1 = tp[y == 0], tp[y == 1]
X0, X1 = X[y == 0], X[y == 1]
X0_tp, X0_fp = X0[tp0], X0[~tp0]
X1_tp, X1_fp = X1[tp1], X1[~tp1]
xmin, xmax = X[:, 0].min(), X[:, 0].max()
ymin, ymax = X[:, 1].min(), X[:, 1].max()
# class 0: dots
plt.plot(X0_tp[:, 0], X0_tp[:, 1], 'o', color='red')
plt.plot(X0_fp[:, 0], X0_fp[:, 1], '.', color='#990000') # dark red
# class 1: dots
plt.plot(X1_tp[:, 0], X1_tp[:, 1], 'o', color='blue')
plt.plot(X1_fp[:, 0], X1_fp[:, 1], '.', color='#000099') # dark blue
# class 0 and 1 : areas
nx, ny = 200, 100
x_min, x_max = plt.xlim()
y_min, y_max = plt.ylim()
xx, yy = np.meshgrid(np.linspace(x_min, x_max, nx),
np.linspace(y_min, y_max, ny))
Z = lda.predict_proba(np.c_[xx.ravel(), yy.ravel()])
Z = Z[:, 1].reshape(xx.shape)
plt.pcolormesh(xx, yy, Z, cmap='red_blue_classes',
norm=colors.Normalize(0., 1.))
plt.contour(xx, yy, Z, [0.5], linewidths=2., colors='k')
# means
plt.plot(lda.means_[0][0], lda.means_[0][1],
'o', color='black', markersize=10)
plt.plot(lda.means_[1][0], lda.means_[1][1],
'o', color='black', markersize=10)
return splot
def plot_ellipse(splot, mean, cov, color):
v, w = linalg.eigh(cov)
u = w[0] / linalg.norm(w[0])
angle = np.arctan(u[1] / u[0])
angle = 180 * angle / np.pi # convert to degrees
# filled Gaussian at 2 standard deviation
ell = mpl.patches.Ellipse(mean, 2 * v[0] ** 0.5, 2 * v[1] ** 0.5,
180 + angle, color=color)
ell.set_clip_box(splot.bbox)
ell.set_alpha(0.5)
splot.add_artist(ell)
splot.set_xticks(())
splot.set_yticks(())
def plot_lda_cov(lda, splot):
plot_ellipse(splot, lda.means_[0], lda.covariance_, 'red')
plot_ellipse(splot, lda.means_[1], lda.covariance_, 'blue')
def plot_qda_cov(qda, splot):
plot_ellipse(splot, qda.means_[0], qda.covariances_[0], 'red')
plot_ellipse(splot, qda.means_[1], qda.covariances_[1], 'blue')
for i, (X, y) in enumerate([dataset_fixed_cov(), dataset_cov()]):
# LDA
lda = LDA(solver="svd", store_covariance=True)
y_pred = lda.fit(X, y).predict(X)
splot = plot_data(lda, X, y, y_pred, fig_index=2 * i + 1)
plot_lda_cov(lda, splot)
plt.axis('tight')
# QDA
qda = QDA()
y_pred = qda.fit(X, y, store_covariances=True).predict(X)
splot = plot_data(qda, X, y, y_pred, fig_index=2 * i + 2)
plot_qda_cov(qda, splot)
plt.axis('tight')
plt.suptitle('LDA vs QDA')
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_MODEL_SELECTION_SCIKIT_LEARN_V1
Purpose : A Program in Python for Model Selection Using SCIKIT LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 17:41 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Model Selection Using SCIKIT LEARN in Python
## Python Development Environment & Runtime - Python, Anaconda
import matplotlib.pyplot as vAR_plt
import numpy as vAR_np
from sklearn.datasets import load_digits
from sklearn.svm import SVC
from sklearn.model_selection import validation_curve
vAR_CSLAB_digits = load_digits()
vAR_CSLAB_X, vAR_CSLAB_y = vAR_CSLAB_digits.data, vAR_CSLAB_digits.target
vAR_CSLAB_param_range = vAR_np.logspace(-6, -1, 5)
vAR_CSLAB_train_scores, vAR_CSLAB_test_scores = validation_curve(
SVC(), vAR_CSLAB_X, vAR_CSLAB_y, param_name="gamma", param_range=vAR_CSLAB_param_range,
cv=10, scoring="accuracy", n_jobs=1)
vAR_CSLAB_train_scores_mean = vAR_np.mean(vAR_CSLAB_train_scores, axis=1)
vAR_CSLAB_train_scores_std = vAR_np.std(vAR_CSLAB_train_scores, axis=1)
vAR_CSLAB_test_scores_mean = vAR_np.mean(vAR_CSLAB_test_scores, axis=1)
vAR_CSLAB_test_scores_std = vAR_np.std(vAR_CSLAB_test_scores, axis=1)
vAR_plt.title("Validation Curve with SVM")
vAR_plt.xlabel("$\gamma$")
vAR_plt.ylabel("Score")
vAR_plt.ylim(0.0, 1.1)
vAR_plt.semilogx(vAR_CSLAB_param_range, vAR_CSLAB_train_scores_mean, label="Training score", color="r")
vAR_plt.fill_between(vAR_CSLAB_param_range, vAR_CSLAB_train_scores_mean - vAR_CSLAB_train_scores_std,
vAR_CSLAB_train_scores_mean + vAR_CSLAB_train_scores_std, alpha=0.2, color="r")
vAR_plt.semilogx(vAR_CSLAB_param_range, vAR_CSLAB_test_scores_mean, label="Cross-validation score",
color="g")
vAR_plt.fill_between(vAR_CSLAB_param_range, vAR_CSLAB_test_scores_mean - vAR_CSLAB_test_scores_std,
vAR_CSLAB_test_scores_mean + vAR_CSLAB_test_scores_std, alpha=0.2, color="g")
vAR_plt.legend(loc="best")
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_NEAREST_NEIGHBOURS_REGRESSION_SCIKIT-LEARN_V1
Purpose : A Program in Python for Nearest Neighbour Regression using SCIKIT-LEARN
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:28 hrs
Version : 1.0
/***********************************
## Program Description : Program for Nearest Neighbour Regression using SCIKIT-LEARN in Python
## Python Development Environment & Runtime - Python, Anaconda
# Generate sample data
import numpy as np
import matplotlib.pyplot as plt
from sklearn import neighbors
np.random.seed(0)
X = np.sort(5 * np.random.rand(40, 1), axis=0)
T = np.linspace(0, 5, 500)[:, np.newaxis]
y = np.sin(X).ravel()
# Add noise to targets
y[::5] += 1 * (0.5 - np.random.rand(8))
# Fit regression model
n_neighbors = 5
for i, weights in enumerate(['uniform', 'distance']):
knn = neighbors.KNeighborsRegressor(n_neighbors, weights=weights)
y_ = knn.fit(X, y).predict(T)
plt.subplot(2, 1, i + 1)
plt.scatter(X, y, c='k', label='data')
plt.plot(T, y_, c='g', label='prediction')
plt.axis('tight')
plt.legend()
plt.title("KNeighborsRegressor (k = %i, weights = '%s')" % (n_neighbors, weights))
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_REGULAR_PLOT_V1
Purpose : A Program in Python for Regular PLot in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:41 hrs
Version : 1.0
/***********************************
## Program Description : Program for Regular PLot in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
X = np.linspace(-np.pi,np.pi,n,endpoint=True)
Y = np.sin(2*X)
axes([0.025,0.025,0.95,0.95])
plot (X, Y+1, color='blue', alpha=1.00)
fill_between(X, 1, Y+1, color='blue', alpha=.25)
plot (X, Y-1, color='blue', alpha=1.00)
fill_between(X, -1, Y-1, (Y-1) > -1, color='blue', alpha=.25)
fill_between(X, -1, Y-1, (Y-1) < -1, color='red', alpha=.25)
xlim(-np.pi,np.pi), xticks([])
ylim(-2.5,2.5), yticks([])
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_SCATTER_PLOT_V1
Purpose : A Program in Python for Scatter Plot in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:12 hrs
Version : 1.0
/***********************************
## Program Description : Program for Regular PLot in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
X = np.random.normal(0,1,n)
Y = np.random.normal(0,1,n)
T = np.arctan2(Y,X)
axes([0.025,0.025,0.95,0.95])
scatter(X,Y, s=75, c=T, alpha=.5)
xlim(-1.5,1.5), xticks([])
ylim(-1.5,1.5), yticks([])
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_BAR_PLOT_V1
Purpose : A Program in Python for Bar Plot in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:47 hrs
Version : 1.0
/****************************************
## Program Description : Program for Bar Plot in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
import numpy as vAR_np
vAR_CSLAB_n = 12
vAR_CSLAB_X = vAR_np.arange(vAR_CSLAB_n)
vAR_CSLAB_Y1 = (1-vAR_CSLAB_X/float(vAR_CSLAB_n)) * vAR_np.random.uniform(0.5,1.0,vAR_CSLAB_n)
vAR_CSLAB_Y2 = (1-vAR_CSLAB_X/float(vAR_CSLAB_n)) * vAR_np.random.uniform(0.5,1.0,vAR_CSLAB_n)
axes([0.025,0.025,0.95,0.95])
bar(vAR_CSLAB_X, +vAR_CSLAB_Y1, facecolor='#9999ff', edgecolor='white')
bar(vAR_CSLAB_X, -vAR_CSLAB_Y2, facecolor='#ff9999', edgecolor='white')
for vAR_CSLAB_x,vAR_CSLAB_y in zip(vAR_CSLAB_X,vAR_CSLAB_Y1):
text(vAR_CSLAB_x+0.4, vAR_CSLAB_y+0.05, '%.2f' % vAR_CSLAB_y, ha='center', va= 'bottom')
for vAR_CSLAB_x,vAR_CSLAB_y in zip(vAR_CSLAB_X,vAR_CSLAB_Y2):
text(vAR_CSLAB_x+0.4, -vAR_CSLAB_y-0.05, '%.2f' % vAR_CSLAB_y, ha='center', va= 'top')
xlim(-.5,vAR_CSLAB_n), xticks([])
ylim(-1.25,+1.25), yticks([])
show()/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_CONTOUR_PLOT_V1
Purpose : A Program in Python for Contour Plot in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 16:09 hrs
Version : 1.0
/***********************************
## Program Description : Program for Contour PLot in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
def f(x,y): return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2)
n = 256
x = np.linspace(-3,3,n)
y = np.linspace(-3,3,n)
X,Y = np.meshgrid(x,y)
axes([0.025,0.025,0.95,0.95])
contourf(X, Y, f(X,Y), 8, alpha=.75, cmap=cm.hot)
C = contour(X, Y, f(X,Y), 8, colors='black', linewidth=.5)
clabel(C, inline=1, fontsize=10)
xticks([]), yticks([])
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_IMSHOW_V1
Purpose : A Program in Python for IMSHOW in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:07 hrs
Version : 1.0
/***********************************
## Program Description : Program for IMSHOW in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
def f(x,y): return (1-x/2+x**5+y**3)*np.exp(-x**2-y**2)
n = 10
x = np.linspace(-3,3,3.5*n)
y = np.linspace(-3,3,3.0*n)
X,Y = np.meshgrid(x,y)
Z = f(X,Y)
axes([0.025,0.025,0.95,0.95])
imshow(Z,interpolation='nearest', cmap='bone', origin='lower')
colorbar(shrink=.92)
xticks([]), yticks([])
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_PIE_CHART_V1
Purpose : A Program in Python for Pie Charts in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 14:31 hrs
Version : 1.0
/****************************************
## Program Description : Program for Pie Charts in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
import numpy as vAR_np
import matplotlib.pyplot as vAR_plt
vAR_CSLAB_n = 20
vAR_CSLAB_Z = vAR_np.ones(vAR_CSLAB_n)
vAR_CSLAB_Z[-1] *= 2
axes([0.025,0.025,0.95,0.95])
pie(vAR_CSLAB_Z, explode=vAR_CSLAB_Z*.05, colors = ['%f' % (i/float(vAR_CSLAB_n)) for i in range(vAR_CSLAB_n)])
gca().set_aspect('equal')
xticks([]), vAR_plt.yticks([])
show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_QUIVER_PLOT_V1
Purpose : A Program in Python for Quiver Plot in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:00 hrs
Version : 1.0
/***********************************
## Program Description : Program for Quiver Plog in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
n = 8
X,Y = np.mgrid[0:n,0:n]
T = np.arctan2(Y-n/2.0, X-n/2.0)
R = 10+np.sqrt((Y-n/2.0)**2+(X-n/2.0)**2)
U,V = R*np.cos(T), R*np.sin(T)
axes([0.025,0.025,0.95,0.95])
quiver(X,Y,U,V,R, alpha=.5)
quiver(X,Y,U,V, edgecolor='k', facecolor='None', linewidth=.5)
xlim(-1,n), xticks([])
ylim(-1,n), yticks([])
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_GRIDS_V1
Purpose : A Program in Python for Grids in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:24 hrs
Version : 1.0
/***********************************
## Program Description : Program for Grids in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
ax = axes([0.025,0.025,0.95,0.95])
ax.set_xlim(0,4)
ax.set_ylim(0,3)
ax.xaxis.set_major_locator(MultipleLocator(1.0))
ax.xaxis.set_minor_locator(MultipleLocator(0.1))
ax.yaxis.set_major_locator(MultipleLocator(1.0))
ax.yaxis.set_minor_locator(MultipleLocator(0.1))
ax.grid(which='major', axis='x', linewidth=0.75, linestyle='-', color='0.75')
ax.grid(which='minor', axis='x', linewidth=0.25, linestyle='-', color='0.75')
ax.grid(which='major', axis='y', linewidth=0.75, linestyle='-', color='0.75')
ax.grid(which='minor', axis='y', linewidth=0.25, linestyle='-', color='0.75')
ax.set_xticklabels([])
ax.set_yticklabels([])
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_MULTI_PLOTS_V1
Purpose : A Program in Python for Multi Plots in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:49 hrs
Version : 1.0
/***********************************
## Program Description : Program for Multi Plots in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
fig =figure()
fig.subplots_adjust(bottom=0.025, left=0.025, top = 0.975, right=0.975)
subplot(2,1,1)
xticks([]), yticks([])
subplot(2,3,4)
xticks([]), yticks([])
subplot(2,3,5)
xticks([]), yticks([])
subplot(2,3,6)
xticks([]), yticks([])
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_POLAR_AXIS_V1
Purpose : A Program in Python for Polar Axis in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 16:12 hrs
Version : 1.0
/***********************************
## Program Description : Program for Polar Axis in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
ax = axes([0.025,0.025,0.95,0.95], polar=True)
N = 20
theta = np.arange(0.0, 2*np.pi, 2*np.pi/N)
radii = 10*np.random.rand(N)
width = np.pi/4*np.random.rand(N)
bars = bar(theta, radii, width=width, bottom=0.0)
for r,bar in zip(radii, bars):
bar.set_facecolor( cm.jet(r/10.))
bar.set_alpha(0.5)
ax.set_xticklabels([])
ax.set_yticklabels([])
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_3D_PLOT_V1
Purpose : A Program in Python for 3D Plot in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 16:37 hrs
Version : 1.0
/***********************************
## Program Description : Program for 3D Plot in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
from pylab import *
from mpl_toolkits.mplot3d import Axes3D
fig = figure()
ax = Axes3D(fig)
X = np.arange(-4, 4, 0.25)
Y = np.arange(-4, 4, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.hot)
ax.contourf(X, Y, Z, zdir='z', offset=-2, cmap=cm.hot)
ax.set_zlim(-2,2)
show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_GRAPHING_MATPLOTLIB_TEXTS_V1
Purpose : A Program in Python for Texts in matplotlib
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 17:03 hrs
Version : 1.0
/****************************************
## Program Description : Program for Texts in matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
import matplotlib
import matplotlib.pyplot as vAR_plt
vAR_CSLAB_fig = vAR_plt.figure()
vAR_CSLAB_fig.suptitle('bold figure suptitle', fontsize=14, fontweight='bold')
vAR_CSLAB_ax = vAR_CSLAB_fig.add_subplot(111)
vAR_CSLAB_fig.subplots_adjust(top=0.85)
vAR_CSLAB_ax.set_title('axes title')
vAR_CSLAB_ax.set_xlabel('xlabel')
vAR_CSLAB_ax.set_ylabel('ylabel')
vAR_CSLAB_ax.text(3, 8, 'boxed italics text in data coords', style='italic',
bbox={'facecolor': 'red', 'alpha': 0.5, 'pad': 10})
vAR_CSLAB_ax.text(2, 6, r'an equation: $E=mc^2$', fontsize=15)
vAR_CSLAB_ax.text(3, 2, 'unicode: Institut für Festkörperphysik')
vAR_CSLAB_ax.text(0.95, 0.01, 'colored text in axes coords',
verticalalignment='bottom', horizontalalignment='right',
transform=vAR_CSLAB_ax.transAxes,
color='green', fontsize=15)
vAR_CSLAB_ax.plot([2], [1], 'o')
vAR_CSLAB_ax.annotate('annotate', xy=(2, 1), xytext=(3, 4),
arrowprops=dict(facecolor='black', shrink=0.05))
vAR_CSLAB_ax.axis([0, 10, 0, 10])
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_HISTOGRAM_MATPLOTLIB_V1
Purpose : A Program in Python for Histogram using Matplotlib Package
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 12:32 hrs
Version : 1.0
/******************************************
## Program Description : Program for Histogram using Matplotlib in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
import matplotlib.pyplot as plt
mu, sigma = 100, 15
CSLAB_X = mu + sigma * np.random.randn(10000)
# the histogram of the data
n, bins, patches = plt.hist(CSLAB_X, 50, normed=1, facecolor='g', alpha=0.75)
plt.xlabel('Smarts')
plt.ylabel('Probability')
plt.title('Histogram of IQ')
plt.text(60, .025, r'$mu=100, sigma=15$')
plt.axis([40, 160, 0, 0.03])
plt.grid(True)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_BED_OCCUPANCY_OPTIMIZATION_V1
Purpose : A Program in Python Bed Occupancy Optimization Usecase
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 9:42 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Bed Occupancy Optimization Usecase in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
import numpy as vAR_np
import matplotlib.pyplot as vAR_plt
vAR_CSLAB_fig = vAR_plt.figure()
vAR_CSLAB_ax = vAR_CSLAB_fig.gca(projection='3d')
vAR_CSLAB_x = vAR_np.linspace(0, 1, 100)
vAR_CSLAB_y = vAR_np.sin(vAR_CSLAB_x * 2 * vAR_np.pi) / 2 + 0.5
vAR_CSLAB_ax.plot(vAR_CSLAB_x, vAR_CSLAB_y, zs=0, zdir='z')
vAR_CSLAB_colors = ('r', 'g', 'b', 'k')
for vAR_CSLAB_c in vAR_CSLAB_colors:
vAR_CSLAB_x = vAR_np.random.sample(20)
vAR_CSLAB_y = vAR_np.random.sample(20)
vAR_CSLAB_ax.scatter(vAR_CSLAB_x, vAR_CSLAB_y, 0, zdir='y', c=vAR_CSLAB_c)
vAR_CSLAB_ax.legend()
vAR_CSLAB_ax.set_xlim3d(0, 1)
vAR_CSLAB_ax.set_ylim3d(0, 1)
vAR_CSLAB_ax.set_zlim3d(0, 1)
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/************************************
File Name : CSLAB_LIFE_TIME_VALUE_CUSTOMER_PREDICTION_V1
Purpose : A Program in Python For Predicting Life Time Value Customers
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:04 hrs
Version : 1.0
/******************************************
## Program Description : Program For Predicting Life Time Value Customers in Python
## Python Development Environment & Runtime - Python, Anaconda
import matplotlib
from numpy.random import randn
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
def to_percent(y, position):
# Ignore the passed in position. This has the effect of scaling the default
# tick locations.
s = str(100 * y)
# The percent symbol needs escaping in latex
if matplotlib.rcParams['text.usetex'] is True:
return s + r'$%$'
else:
return s + '%'
x = randn(5000)
plt.hist(x, bins=50, normed=True)
formatter = FuncFormatter(to_percent)
plt.gca().yaxis.set_major_formatter(formatter)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_CUSTOMER_UPSELLING_CHARACTERISTICS_PREDICTION_V1
Purpose : A Program in Python For Predicting Customers Upselling Characteristics
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 15:41 hrs
Version : 1.0
/******************************************
## Program Description : Program For Predicting Customers Upselling Characteristics in Python
## Python Development Environment & Runtime - Python, Anaconda
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.01, 5.0, 0.01)
s = np.exp(-t)
plt.plot(t, s)
plt.xlim(5, 0)
plt.xlabel('Incresing time (s)')
plt.ylabel('Upselling (%)')
plt.title('Should be growing...')
plt.grid(True)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_SALES_LEAD_PRIORTIZATION_V1
Purpose : A Program in Python For Lead Priortization
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 16:17 hrs
Version : 1.0
/******************************************
## Program Description : Program For Lead Priortization in Python
## Python Development Environment & Runtime - Python, Anaconda
from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
import matplotlib.dates as mdates
from matplotlib.dates import bytespdate2num
datafile = cbook.get_sample_data('msft.csv', asfileobj=False)
print('loading', datafile)
dates, closes = np.loadtxt(datafile, delimiter=',',
converters={0: bytespdate2num('%d-%b-%y')},
skiprows=1, usecols=(0, 2), unpack=True)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot_date(dates, closes, '-')
fig.autofmt_xdate()
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_INVENTORY_DEMAND_FORECASTING_V1
Purpose : A Program in Python For Inventory Demand Forecasting
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 16:55 hrs
Version : 1.0
/******************************************
## Program Description : Program For Inventory Demand Forecasting in Python
## Python Development Environment & Runtime - Python, Anaconda
import matplotlib.pyplot as plt
import numpy as np
t1 = np.arange(0.0, 2.0, 0.1)
t2 = np.arange(0.0, 2.0, 0.01)
l1, = plt.plot(t2, np.exp(-t2))
l2, l3 = plt.plot(t2, np.sin(2 * np.pi * t2), '--go', t1, np.log(1 + t1), '.')
l4, = plt.plot(t2, np.exp(-t2) * np.sin(2 * np.pi * t2), 'rs-.')
plt.legend((l2, l4), ('Actual Demand', 'Forecated Demand'), loc='upper right', shadow=True)
plt.xlabel('time')
plt.ylabel('Demand %')
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_CREDIT_CARD_FRAUD_RISK_V1
Purpose : A Program in Python For Credit Card Fraud Risk
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 17:21 hrs
Version : 1.0
/******************************************
## Program Description : Program For Credit Card Fraud Risk in Python
## Python Development Environment & Runtime - Python, Anaconda
import matplotlib.pyplot as plt
from numpy import arange, pi, cos, sin
from numpy.random import rand
rx, ry = 3., 1.
area = rx * ry * pi
theta = arange(0, 2*pi + 0.01, 0.1)
verts = list(zip(rx/area*cos(theta), ry/area*sin(theta)))
x, y, s, c = rand(4, 30)
s *= 10**2.
fig, ax = plt.subplots()
ax.scatter(x, y, s, c, marker=None, verts=verts)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_EMPLOYEE_CHURN_PREDICTION_V1
Purpose : A Program in Python For Predicting Employee Churn Rate
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 17:43 hrs
Version : 1.0
/******************************************
## Program Description : Program For Predicting Employee Churn Rate in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
def layers(n, m):
"""
Return *n* random Gaussian mixtures, each of length *m*.
"""
def bump(a):
x = 1 / (.1 + np.random.random())
y = 2 * np.random.random() - .5
z = 10 / (.1 + np.random.random())
for i in range(m):
w = (i / float(m) - y) * z
a[i] += x * np.exp(-w * w)
a = np.zeros((m, n))
for i in range(n):
for j in range(5):
bump(a[:, i])
return a
d = layers(3, 100)
plt.subplots()
plt.stackplot(range(100), d.T, baseline='wiggle')
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_PATIENT_MEDICATION_COMPLAINCE_PREDICTION_V1
Purpose : A Program in Python For Predicting Patient Medication Compliance
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 18:12 hrs
Version : 1.0
/******************************************
## Program Description : Program For Predicting Patient Medication Compliance in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
import matplotlib.pyplot as plt
def fnx():
return np.random.randint(5, 50, 10)
y = np.row_stack((fnx(), fnx(), fnx()))
x = np.arange(10)
y1, y2, y3 = fnx(), fnx(), fnx()
fig, ax = plt.subplots()
ax.stackplot(x, y)
plt.show()
fig, ax = plt.subplots()
ax.stackplot(x, y1, y2, y3)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_PHYSICIAN_ATTRITION_PREDICTION_V1
Purpose : A Program in Python For Predicting Physician Attrition
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 18:12 hrs
Version : 1.0
/******************************************
## Program Description : Program For Predicting Physician Attrition in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):
xs = np.arange(20)
ys = np.random.rand(20)
# You can provide either a single color or an array. To demonstrate this,
# the first bar of each set will be colored cyan.
cs = [c] * len(xs)
cs[0] = 'c'
ax.bar(xs, ys, zs=z, zdir='y', color=cs, alpha=0.8)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_PATIENT_READMITTANCE_RATE_PREDICTION_V1
Purpose : A Program in Python For Predicting Patient Readmittacnce
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 18:58 hrs
Version : 1.0
/******************************************
## Program Description : Program For Predicting Patient Readmittacnce in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
from matplotlib import cm
fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y, Z = axes3d.get_test_data(0.05)
cset = ax.contour(X, Y, Z, extend3d=True, cmap=cm.coolwarm)
ax.clabel(cset, fontsize=9, inline=1)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_PATIENT_INSURANCE_CLAIM_PREDICTION_V1
Purpose : A Program in Python For Predicting Patient Insurance Claim
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 18:58 hrs
Version : 1.0
/******************************************
## Program Description : Program For Predicting Patient Insurance Claim in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
def f(t):
s1 = np.cos(2*np.pi*t)
e1 = np.exp(-t)
return np.multiply(s1, e1)
ax = fig.add_subplot(2, 1, 2, projection='3d')
X = np.arange(-5, 5, 0.25)
xlen = len(X)
Y = np.arange(-5, 5, 0.25)
ylen = len(Y)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1,
linewidth=0, antialiased=False)
ax.set_zlim3d(-1, 1)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/************************************
File Name : CSLAB_DRUG_DEMAND_FORECASTING_V1
Purpose : A Program in Python For Drug Demad Forecasting
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 19:22 hrs
Version : 1.0
/******************************************
## Program Description : Program For Drug Demad Forecasting in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
X, Y = np.mgrid[0:6*np.pi:0.25, 0:4*np.pi:0.25]
Z = np.sqrt(np.abs(np.cos(X) + np.cos(Y)))
surf = ax.plot_surface(X + 1e5, Y + 1e5, Z, cmap='autumn', cstride=2, rstride=2)
ax.set_zlim(0, 2)
plt.show()
/***********************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/***********************************
/**************************************
File Name : CSLAB_CUSTOMER_RETENTION_ANALYSIS_V1
Purpose : A Program in Python For Customer Retention Analysis
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 19:45 hrs
Version : 1.0
/***********************************************
## Program Description : Program For Customer Retention Analysis in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.collections import PolyCollection
from matplotlib.colors import colorConverter
import matplotlib.pyplot as vAR_plt
import numpy as vAR_np
vAR_CSLAB_fig = vAR_plt.figure()
vAR_CSLAB_ax = vAR_CSLAB_fig.gca(projection='3d')
def cc(arg):
return colorConverter.to_rgba(arg, alpha=0.6)
vAR_CSLAB_xs = vAR_np.arange(0, 10, 0.4)
vAR_CSLAB_verts = []
vAR_CSLAB_zs = [0.0, 1.0, 2.0, 3.0]
for z in vAR_CSLAB_zs:
vAR_CSLAB_ys = vAR_np.random.rand(len(vAR_CSLAB_xs))
vAR_CSLAB_ys[0], vAR_CSLAB_ys[-1] = 0, 0
vAR_CSLAB_verts.append(list(zip(vAR_CSLAB_xs, vAR_CSLAB_ys)))
vAR_CSLAB_poly = PolyCollection(vAR_CSLAB_verts, facecolors=[cc('r'), cc('g'), cc('b'),
cc('y')])
vAR_CSLAB_poly.set_alpha(0.7)
vAR_CSLAB_ax.add_collection3d(vAR_CSLAB_poly, zs=vAR_CSLAB_zs, zdir='y')
vAR_CSLAB_ax.set_xlim3d(0, 10)
vAR_CSLAB_ax.set_ylim3d(-1, 4)
vAR_CSLAB_ax.set_zlabel('Z')
vAR_CSLAB_ax.set_zlim3d(0, 1)
vAR_plt.show()
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/*********************************
File Name : CSLAB_HOSPITAL_BED_TURN_ANALYSIS_V1
Purpose : A Program in Python For Hospital Bed Turn Analysis
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 20:11 hrs
Version : 1.0
/*************************************
## Program Description : Program For Hospital Bed Turn Analysis in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x, y = np.random.rand(2, 100) * 4
hist, xedges, yedges = np.histogram2d(x, y, bins=4)
elements = (len(xedges) - 1) * (len(yedges) - 1)
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25)
xpos = xpos.flatten()
ypos = ypos.flatten()
zpos = np.zeros(elements)
dx = 0.5 * np.ones_like(zpos)
dy = dx.copy()
dz = hist.flatten()
ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b', zsort='average')
plt.show()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_PATIENT_SURVIVAL_ANALYSIS_V1
Purpose : A Program in Python For Patient Survival Analysis
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 20:31 hrs
Version : 1.0
/*************************************
## Program Description : Program For Patient Survival Analysis in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
def randrange(n, vmin, vmax):
return (vmax - vmin)*np.random.rand(n) + vmin
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
n = 100
for c, m, zl, zh in [('r', 'o', -50, -25), ('b', '^', -30, -5)]:
xs = randrange(n, 23, 32)
ys = randrange(n, 0, 100)
zs = randrange(n, zl, zh)
ax.scatter(xs, ys, zs, c=c, marker=m)
plt.show()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_PATIENT_MEDICATION_EFFECTIVENESS_ANALYSIS_V1
Purpose : A Program in Python For Patient Medication Effectiveness Analysis
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 21:03 hrs
Version : 1.0
/*************************************
## Program Description : Program For Patient Medication Effectiveness Analysis in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25)
Y = np.arange(-5, 5, 0.25)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
linewidth=0, antialiased=False)
ax.set_zlim(-1.01, 1.01)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_SALES_GROWTH_ANALYSIS_V1
Purpose : A Program in Python For Sales Growth Analysis
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 21:12 hrs
Version : 1.0
/*************************************
## Program Description : Program For Sales Growth Analysis in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = 10 * np.outer(np.cos(u), np.sin(v))
y = 10 * np.outer(np.sin(u), np.sin(v))
z = 10 * np.outer(np.ones(np.size(u)), np.cos(v))
ax.plot_surface(x, y, z, rstride=4, cstride=4, color='b')
plt.show()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_CUSTOMER_CROSS_SELLING_ANALYSIS_V1
Purpose : A Program in Python For Customer Cross Selling Analysis
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 21:35 hrs
Version : 1.0
/*************************************
## Program Description : Program For Customer Cross Selling Analysis in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.gca(projection='3d')
X = np.arange(-5, 5, 0.25)
xlen = len(X)
Y = np.arange(-5, 5, 0.25)
ylen = len(Y)
X, Y = np.meshgrid(X, Y)
R = np.sqrt(X**2 + Y**2)
Z = np.sin(R)
colortuple = ('y', 'b')
colors = np.empty(X.shape, dtype=str)
for y in range(ylen):
for x in range(xlen):
colors[x, y] = colortuple[(x + y) % len(colortuple)]
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=colors,
linewidth=0, antialiased=False)
ax.set_zlim3d(-1, 1)
ax.w_zaxis.set_major_locator(LinearLocator(6))
plt.show()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_PRODUCT_CUSTOMER_SEGMENTATION_V1
Purpose : A Program in Python For Product Customer Segmentation Analysis
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 21:52 hrs
Version : 1.0
/*************************************
## Program Description : Program For Product Customer Segmentation Analysis in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
import matplotlib
import numpy as np
from matplotlib import cm
from matplotlib import pyplot as plt
step = 0.04
maxval = 1.0
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
# create supporting points in polar coordinates
r = np.linspace(0, 1.25, 50)
p = np.linspace(0, 2*np.pi, 50)
R, P = np.meshgrid(r, p)
# transform them to cartesian system
X, Y = R*np.cos(P), R*np.sin(P)
Z = ((R**2 - 1)**2)
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.YlGnBu_r)
ax.set_zlim3d(0, 1)
ax.set_zlabel(r'$V(phi)$')
plt.show()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_EMPLOYEE_TALENT_MANGEMENT_V1
Purpose : A Program in Python For Employee Talent Mangement Analysis
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 22:07 hrs
Version : 1.0
/*************************************
## Program Description : Program For Employee Talent Mangement Analysis in Python
## Python Development Environment & Runtime - Python, Anaconda
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.tri as tri
import numpy as np
import math
# First create the x and y coordinates of the points.
n_angles = 48
n_radii = 8
min_radius = 0.25
radii = np.linspace(min_radius, 0.95, n_radii)
angles = np.linspace(0, 2*math.pi, n_angles, endpoint=False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
angles[:, 1::2] += math.pi/n_angles
x = (radii*np.cos(angles)).flatten()
y = (radii*np.sin(angles)).flatten()
z = (np.cos(radii)*np.cos(angles*3.0)).flatten()
# Create a custom triangulation
triang = tri.Triangulation(x, y)
# Mask off unwanted triangles.
xmid = x[triang.triangles].mean(axis=1)
ymid = y[triang.triangles].mean(axis=1)
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
triang.set_mask(mask)
plt.figure()
plt.gca(projection='3d')
plt.tricontourf(triang, z)
plt.show()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_PATIENT_BED_OCCUPANCY_V1
Purpose : A Program in Python For Patient Bed Occupancy
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 22:21 hrs
Version : 1.0
/*************************************
## Program Description : Program For Patient Bed Occupancy in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import matplotlib.pyplot as plt
import numpy as np
n_angles = 36
n_radii = 8
radii = np.linspace(0.125, 1.0, n_radii)
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
x = np.append(0, (radii*np.cos(angles)).flatten())
y = np.append(0, (radii*np.sin(angles)).flatten())
z = np.sin(-x*y)
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.2)
plt.show()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_PRODUCT_MARKET_BASKET_ANALYSIS_V1
Purpose : A Program in Python For Product Basket Analysis
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 22:47 hrs
Version : 1.0
/*************************************
## Program Description : Program For Product Basket Analysis in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.tri as mtri
# u, v are parameterisation variables
u = (np.linspace(0, 2.0 * np.pi, endpoint=True, num=50) * np.ones((10, 1))).flatten()
v = np.repeat(np.linspace(-0.5, 0.5, endpoint=True, num=10), repeats=50).flatten()
x = (1 + 0.5 * v * np.cos(u / 2.0)) * np.cos(u)
y = (1 + 0.5 * v * np.cos(u / 2.0)) * np.sin(u)
z = 0.5 * v * np.sin(u / 2.0)
# Triangulate parameter space to determine the triangles
tri = mtri.Triangulation(u, v)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax.plot_trisurf(x, y, z, triangles=tri.triangles, cmap=plt.cm.Spectral)
ax.set_zlim(-1, 1)
n_angles = 36
n_radii = 8
min_radius = 0.25
radii = np.linspace(min_radius, 0.95, n_radii)
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
angles[:, 1::2] += np.pi/n_angles
x = (radii*np.cos(angles)).flatten()
y = (radii*np.sin(angles)).flatten()
z = (np.cos(radii)*np.cos(angles*3.0)).flatten()
triang = mtri.Triangulation(x, y)
xmid = x[triang.triangles].mean(axis=1)
ymid = y[triang.triangles].mean(axis=1)
mask = np.where(xmid*xmid + ymid*ymid < min_radius*min_radius, 1, 0)
triang.set_mask(mask)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')
ax.plot_trisurf(triang, z, cmap=plt.cm.CMRmap)
plt.show()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_AUTOMOBILE_CLAIMS_HANDLING_ANALYSIS_V1
Purpose : A Program in Python For Auto Claims Handling
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 23:04 hrs
Version : 1.0
/*************************************
## Program Description : Program For Auto Claims Handling Analysis in Python
## Python Development Environment & Runtime - Python, Anaconda
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
import time
def generate(X, Y, phi):
R = 1 - np.sqrt(X**2 + Y**2)
return np.cos(2 * np.pi * X + phi) * R
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
xs = np.linspace(-1, 1, 50)
ys = np.linspace(-1, 1, 50)
X, Y = np.meshgrid(xs, ys)
Z = generate(X, Y, 0.0)
wframe = None
tstart = time.time()
for phi in np.linspace(0, 360 / 2 / np.pi, 100):
oldcol = wframe
Z = generate(X, Y, phi)
wframe = ax.plot_wireframe(X, Y, Z, rstride=2, cstride=2)
ax.collections.remove(oldcol)
plt.pause(.001)
print('FPS: %f' % (100 / (time.time() - tstart)))
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_CUSTOMER_MARKET_SHARE_V1
Purpose : A Program in Python For Market Share Analysis
Author : DeepSphere.AI, Inc.
Date and Time : 14/12/2018 23:17 hrs
Version : 1.0
/*************************************
## Program Description : Program For Market Share Analysis in Python
## Python Development Environment & Runtime - Python, Anaconda
import matplotlib.pyplot as plt
import numpy as np
data = ((3, 1000), (10, 3), (100, 30), (500, 800), (50, 1))
plt.yscale('log')
dim = len(data[0])
w = 0.75
dimw = w / dim
x = np.arange(len(data))
for i in range(len(data[0])):
y = [d[i] for d in data]
b = plt.bar(x + i * dimw, y, dimw, bottom=0.001)
plt.xticks(x + w / 2)
plt.ylim((0.001, 1000))
plt.show()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_EXCEL_V1
Purpose : A Program in Python for Collecting Data from an Excel File
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 9:51 hrs
Version : 1.0
/*************************************
## Program Description : Program for Collecting Data from Excel File into a Dataframe in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
vAR_CSLAB_Data = vAR_pd.read_excel('C:/Python_Programs/Train_Data_Unplanned_Expenses.xlsx')
vAR_CSLAB_Data
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_CSV_V1
Purpose : A Program in Python for Collecting Data from a CSV File
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 10:01 hrs
Version : 1.0
/*************************************
## Program Description : Program for Collecting Data from a CSV File in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
vAR_CSLAB_Data = vAR_pd.read_csv('C:/Python_Programs/Test_Data_Unplanned_Expenses_RF.csv')
vAR_CSLAB_Data
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_CLIPBOARD_V1
Purpose : A Program in Python for Collecting Data from Clipboard
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 10:08 hrs
Version : 1.0
/*************************************
## Program Description : Program for Collecting Data from Clipboard in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
vAR_CSLAB_Data = vAR_pd.read_clipboard('C:/Python_Programs/Train_Data_Unplanned_Expenses.txt')
vAR_CSLAB_Data
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_HTML_V1
Purpose : A Program in Python for Colecting Data from HTML
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 10:17 hrs
Version : 1.0
/*************************************
## Program Description : Program for Collecting Data from HTML in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
vAR_CSLAB_Data = vAR_pd.read_html('https://www.fnb.co.za/Controller?nav=rates.forex.list.ForexRatesList',index_col=1, header=0)
vAR_CSLAB_Data
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_XML_V1
Purpose : A Program in Python for Collecting Data from XML
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 10:22 hrs
Version : 1.0
/*************************************
## Program Description : Program for Colecting Data from XML in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
import requests
vAR_CSLAB_user_agent_url = 'http://www.user-agents.org/allagents.xml'
vAR_CSLAB_xml_data = requests.get(vAR_CSLAB_user_agent_url).content
vAR_CSLAB_xml_data
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_JSON_V1
Purpose : A Program in Python for Collecting JSON Data
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 10:31 hrs
Version : 1.0
/*************************************
## Program Description : Program for Collecting Data from JSON in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
vAR_CSLAB_url = 'https://raw.githubusercontent.com/chrisalbon/simulated_datasets/master/data.json'
vAR_CSLAB_df = vAR_pd.read_json(vAR_CSLAB_url, orient='columns')
vAR_CSLAB_df
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_PDF_V1
Purpose : A Program in Python for Collecting Data from a PDF File
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 10:42 hrs
Version : 1.0
/*************************************
## Program Description : Program for Collecting Data from a PDF File in Python
## Python Development Environment & Runtime - Python, Anaconda
import PyPDF2
vAR_CSLAB_pdf_file = open('C:/Python_Programs/201308FCR.pdf','rb')
vAR_CSLAB_read_pdf = PyPDF2.PdfFileReader(vAR_CSLAB_pdf_file)
vAR_CSLAB_number_of_pages = vAR_CSLAB_read_pdf.getNumPages()
vAR_CSLAB_page = vAR_CSLAB_read_pdf.getPage(0)
vAR_CSLAB_page_content = vAR_CSLAB_page.extractText()
print (vAR_CSLAB_page_content.encode('utf-8'))
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_PLAINTEXT_V1
Purpose : A Program in Python for Collecting Data from Plaintext
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 10:55 hrs
Version : 1.0
/*************************************
## Program Description : Program for Collecting Data from Plaintext in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
vAR_CSLAB_File = open('C:/Python_Programs/Train_Data_Unplanned_Expenses.dat')
vAR_CSLAB_LIST = vAR_CSLAB_File.readlines()
vAR_CSLAB_LIST = vAR_pd.DataFrame(vAR_CSLAB_LIST)
vAR_CSLAB_LIST
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_WORD_V1
Purpose : A Program in Python for Collecting Data from a Word Document
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 11:12 hrs
Version : 1.0
/*************************************
## Program Description : Program for Collecting Data from a Word Document in Python
## Python Development Environment & Runtime - Python, Anaconda
from docx import Document
vAR_CSLAB_document = Document('C:/Python_Programs/Docker.docx')
for table in vAR_CSLAB_document.tables:
for row in table.rows:
for cell in row.cells:
print (cell.text)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_HDF_V1
Purpose : A Program in Python for Collecting Data from HDF
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 11:23 hrs
Version : 1.0
/*************************************
## Program Description : Program for Collecting Data from HDF in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
vAR_CSLAB_df = vAR_pd.DataFrame([[1, 1.0, 'a']], columns=['x', 'y', 'z'])
vAR_CSLAB_df.to_hdf('./store.h5', 'data')
vAR_CSLAB_reread = vAR_pd.read_hdf('./store.h5')
vAR_CSLAB_reread
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/**************************************
File Name : CSLAB_DATA_COLLECTION_FROM_IMAGE_V1
Purpose : A Program in Python for Collecting Data from an Image File
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 11:34 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Collecting Data from an Image in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
import os
vAR_INI_File_Path = os.environ.get('PYTHON_TUTORIAL')
import pandas as vAR_pd
import configparser
import matplotlib.pyplot as vAR_plt
vAR_Config = configparser.ConfigParser(allow_no_value=True)
vAR_Config.read(vAR_INI_File_Path)
vAR_CSLAB_DC_IMG = vAR_Config['Data File Path']['vAR_CSLAB_PROGRAM_171_DATA_COLLECTION_IMG']
from scipy import misc
import numpy as vAR_np
import matplotlib.pyplot as vAR_plt
vAR_CSLAB_DC_IMG_W = {'img':[misc.imread(vAR_CSLAB_DC_IMG)]}
vAR_CSLAB_DC_IMG_W
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_MP3_V1
Purpose : A Program in Python for Collecting Data from a MP3 File
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 11:48 hrs
Version : 1.0
/*************************************
## Program Description : Program for Collecting Data from a MP3 File in Python
## Python Development Environment & Runtime - Python, Anaconda
from pydub import AudioSegment
vAR_CSLAB_sound = AudioSegment.from_mp3("C:/Python_Programs/test.mp3",'rb')
vAR_CSLAB_raw_data = vAR_CSLAB_sound._data
vAR_CSLAB_raw_data
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_MP3_V1
Purpose : A Program in Python for Colecting Data from a MP3 File
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 12:14 hrs
Version : 1.0
/*************************************
## Program Description : Program for Collecting Data from SAP HANA in Python
## Python Development Environment & Runtime - Python, Anaconda
import pypyodbc as vAR_pyodbc
vAR_CSLAB_CONN = vAR_pyodbc.connect('DSN=DS;UID=DURGA;PWD=Delhi123')
vAR_CSLAB_CURSOR = CSLAB_CONN.cursor()
vAR_CSLAB_STMNT = 'SELECT * FROM DURGA.TICKETS'
vAR_CSLAB_CURSOR.execute(vAR_CSLAB_STMNT)
vAR_CSLAB_RESULT = vAR_CSLAB_CURSOR.fetchall()
print (vAR_CSLAB_RESULT)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_COLLECTION_FROM_HADOOP_V1
Purpose : A Program in Python for Collecting Data from Hadoop
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 12:28 hrs
Version : 1.0
/*************************************
## Program Description : Program for Collecting Data from Hadoop in Python
## Python Development Environment & Runtime - Python, Anaconda
import pypyodbc as vAR_pyodbc
vAR_CSLAB_CONN = vAR_pyodbc.connect('DSN=Hive;UID=hive;PWD=hive',autocommit=True)
vAR_CSLAB_CURSOR = vAR_CSLAB_CONN.cursor()
vAR_CSLAB_STMNT = 'SHOW TABLES'
vAR_CSLAB_CURSOR.execute(vAR_CSLAB_STMNT)
vAR_CSLAB_RESULT = vAR_CSLAB_CURSOR.fetchall()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_INTEGRATION_CONCATENATE_V1
Purpose : A Program in Python for Integrating Data using Concatenate function
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 12:50 hrs
Version : 1.0
/*************************************
## Program Description : Program for Integrating Data using Concatenate function in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_CSLAB_df1 = pd.DataFrame({'Asset No': ['Asset 101', 'Asset 102', 'Asset 103'],'Asset Type': ['Building', 'Vehicle', 'Equipment']})
vAR_CSLAB_df2 = pd.DataFrame({'Asset No': ['Asset 104', 'Asset 105', 'Asset 107'],'Asset Type': ['Building', 'Vehicle', 'Equipment']})
vAR_CSLAB_df3 = pd.DataFrame({'Asset No': ['Asset 108', 'Asset 109', 'Asset 110'],'Asset Type': ['Building', 'Vehicle', 'Equipment']})
vAR_CSLAB_frames = [vAR_CSLAB_df1, vAR_CSLAB_df2, vAR_CSLAB_df3]
import pandas as vAR_pd
vAR_CSLAB_result = vAR_pd.concat(vAR_CSLAB_frames)
vAR_CSLAB_result = vAR_pd.DataFrame(vAR_CSLAB_result)
vAR_CSLAB_result
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_INTEGRATION_MERGE_V1
Purpose : A Program in Python for Integrating Data using Merge function
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 13:45 hrs
Version : 1.0
/*************************************
## Program Description : Program for Integrating Data using Merge function in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
vAR_CSLAB_df1 = vAR_pd.DataFrame({'Asset No': ['Asset 101', 'Asset 102', 'Asset 103'],'Asset Location': ['CA', 'LA', 'UT']})
vAR_CSLAB_df2 = vAR_pd.DataFrame({'Asset No': ['Asset 101', 'Asset 102', 'Asset 103'],'Age in Years': [20, 27, 24]})
vAR_CSLAB_df3 = vAR_pd.DataFrame({'Asset No': ['Asset 101', 'Asset 102', 'Asset 103'],'No of Repairs': [5, 4, 10]})
vAR_CSLAB_frames = [vAR_CSLAB_df1, vAR_CSLAB_df2, vAR_CSLAB_df3]
vAR_CSLAB_df4 = vAR_pd.merge(vAR_CSLAB_df1,vAR_CSLAB_df2, how='inner')
vAR_CSLAB_df5 = vAR_pd.merge(vAR_CSLAB_df3,vAR_CSLAB_df4, how='outer')
vAR_CSLAB_df5
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_INTEGRATION_MERGE_V1
Purpose : A Program in Python for Integrating Data using Join function
Author : DeepSphere.AI, Inc.
Date and Time : 17/12/2018 14:05 hrs
Version : 1.0
/*************************************
## Program Description : Program for Integrating Data using Join function in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
vAR_CSLAB_df1 = vAR_pd.DataFrame({'Asset No': ['Asset 101', 'Asset 102', 'Asset 103'],'Asset Location': ['CA', 'LA', 'UT']})
vAR_CSLAB_df2 = vAR_pd.DataFrame({'Asset No': ['Asset 104', 'Asset 105', 'Asset 107'],'Age in Years': [20, 27, 24]})
vAR_CSLAB_df3 = vAR_pd.DataFrame({'Asset No': ['Asset 108', 'Asset 109', 'Asset 110'],'No of Repairs': [5, 4, 10]})
vAR_CSLAB_frames = [vAR_CSLAB_df1, vAR_CSLAB_df2, vAR_CSLAB_df3]
vAR_CSLAB_result = vAR_pd.concat(vAR_CSLAB_frames, axis=1, join='inner')
vAR_CSLAB_result = vAR_pd.DataFrame(vAR_CSLAB_result)
vAR_CSLAB_result
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_MAPPING_DICTIONARY_LITERAL_VALUES_V1
Purpose : A Program in Python for Mapping Data using Dictionary Literal Values
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 9:20 hrs
Version : 1.0
/*************************************
## Program Description : Program for Mapping Data using Dictionary Literal Values in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_CSLAB_diceRoll = { (1,1): "snake eyes", (6,6): "box cars" }
vAR_CSLAB_myBoat = { "NAME":"KaDiMa", "LOA":18, "SAILS":["main","jib","spinnaker"] }
vAR_CSLAB_theBets = { }
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_MAPPING_DICTIONARY_OPERATIONS_V1
Purpose : A Program in Python for Mapping Data using Dictionary Operations
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 9:38 hrs
Version : 1.0
/*************************************
## Program Description : Program for Mapping Data using Dictionary Operations in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_CSLAB_d= {}
vAR_CSLAB_d[2] = [ (1,1) ]
vAR_CSLAB_d[3] = [ (1,2), (2,1) ]
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_MAPPING_DICTIONARY_COMPARISION_OPERATIONS_V1
Purpose : A Program in Python for Mapping Data using Dictionary Comparision Operations
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 9:47 hrs
Version : 1.0
/*************************************
## Program Description : Program for Mapping Data using Dictionary Comparision Operations in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_CSLAB_colors = { "blue": (0x30,0x30,0xff), "green": (0x30,0xff,0x97),"red": (0xff,0x30,0x97), "yellow": (0xff,0xff,0x30) }
"blue" in CSLAB_colors
(0x30,0x30,0xff) in vAR_CSLAB_colors
"orange" not in vAR_CSLAB_colors
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_MAPPING_DICTIONARY_STATMENTS_V1
Purpose : A Program in Python for Mapping Data using Dictionary Statements
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 9:59 hrs
Version : 1.0
/*************************************
## Program Description : Program for Mapping Data using Dictionary Dictionary Statements in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_CSLAB_colors = { "blue": (0x30,0x30,0xff), "green": (0x30,0xff,0x97),"red": (0xff,0x30,0x97), "yellow": (0xff,0xff,0x30) }
for c in vAR_CSLAB_colors:
print (c, vAR_CSLAB_colors[c])
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_PROVISIONING_EXTRACTION_V1
Purpose : A Program in Python for Data Provisioning - Extraction
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 10:21 hrs
Version : 1.0
/*************************************
## Program Description : Program for Data Provisioning - Extraction in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
vAR_CSLAB_Data = vAR_pd.read_excel('C:/Python_Programs/Train_Data_Unplanned_Expenses.xlsx')
vAR_CSLAB_Data
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_PROVISIONING_TRANSFORMATION_V1
Purpose : A Program in Python for Data Provisioning - Transformation
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 10:30 hrs
Version : 1.0
/*************************************
## Program Description : Program for Data Provisioning - Transformation in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
vAR_CSLAB_Data = vAR_pd.read_excel('C:/Python_Programs/Train_Data_Unplanned_Expenses.xlsx')
vAR_CSLAB_Data.head(4)
vAR_CSLAB_Data.groupby('Asset Type')["Casualities"].transform('sum')
vAR_CSLAB_Data["Total Casualities"] = vAR_CSLAB_Data.groupby('Asset Type')["Casualities"].transform('sum')
vAR_CSLAB_Data.head(2)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DATA_PROVISIONING_LOADING_V1
Purpose : A Program in Python for Data Provisioning - Loading
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 11:03 hrs
Version : 1.0
/*************************************
## Program Description : Program for Data Provisioning - Loading in Python
## Python Development Environment & Runtime - Python, Anaconda
import pandas as vAR_pd
vAR_CSLAB_CONN = vAR_pyodbc.connect('DSN=DS;UID=DURGA;PWD=Delhi123')
vAR_CSLAB_CURSOR = CSLAB_CONN.cursor()
vAR_CSLAB_STMNT = 'INSERT INTO DURGA.LEASE'
vAR_CSLAB_CURSOR.execute(vAR_CSLAB_STMNT)
vAR_CSLAB_RESULT = vAR_CSLAB_CURSOR.fetchall()
print (vAR_CSLAB_RESULT)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_ITERATORS_V1
Purpose : A Program in Python for Iterators
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 11:24 hrs
Version : 1.0
/*************************************
## Program Description : Program for Iterators in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_CSLAB_nums = [1, 2, 3]
iter(vAR_CSLAB_nums)
vAR_CSLAB_it = iter(vAR_CSLAB_nums)
next(vAR_CSLAB_it)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_ITERATORS_V1
Purpose : A Program in Python for Generator Expressions
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 11:33 hrs
Version : 1.0
/*************************************
## Program Description : Program for Generator Expressions in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_CSLAB_nums = [1, 2, 3]
iter(vAR_CSLAB_nums)
vAR_CSLAB_it = iter(vAR_CSLAB_nums)
next(vAR_CSLAB_it)
(i for i in vAR_CSLAB_nums)
[i for i in vAR_CSLAB_nums]
{i for i in range(3)}
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_ITERATORS_V1
Purpose : A Program in Python for Generators
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 11:41 hrs
Version : 1.0
/*************************************
## Program Description : Program for Generators in Python
## Python Development Environment & Runtime - Python, Anaconda
def vAR_CSLAB_f():
... yield 1
... yield 2
vAR_CSLAB_f()
vAR_CSLAB_gen = vAR_CSLAB_f()
next(vAR_CSLAB_gen)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_BIDIRECTIONAL_COMMUNICATION_V1
Purpose : A Program in Python for Bidirectional Communication
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 11:55 hrs
Version : 1.0
/*************************************
## Program Description : Program for Bidirectional Communication in Python
## Python Development Environment & Runtime - Python, Anaconda
import itertools
def vAR_CSLAB_g():
print('--start--')
for i in itertools.count():
print('--yielding %i--' % i)
try:
vAR_CSLAB_ans = yield i
except GeneratorExit:
print('--closing--')
raise
except Exception as e:
print('--yield raised %r--' % e)
else:
print('--yield returned %s--' % vAR_CSLAB_ans)
vAR_CSLAB_it = vAR_CSLAB_g()
next(vAR_CSLAB_it)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_CHAINING_GENERATORS_V1
Purpose : A Program in Python for Chaining Generators
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 12:14 hrs
Version : 1.0
/*************************************
## Program Description : Program for Chaining Generators in Python
## Python Development Environment & Runtime - Python, Anaconda
import itertools
def vAR_CSLAB_g():
print('--start--')
for i in itertools.count():
print('--yielding %i--' % i)
try:
vAR_CSLAB_ans = yield i
except GeneratorExit:
print('--closing--')
raise
except Exception as e:
print('--yield raised %r--' % e)
else:
print('--yield returned %s--' % vAR_CSLAB_ans)
vAR_CSLAB_it = vAR_CSLAB_g()
next(vAR_CSLAB_it)
vAR_CSLAB_it.send(11)
#subgen = some_other_generator()
#for v in subgen:
#yield v
CSLAB_it = g()
next(CSLAB_it)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DECORATORS_V1
Purpose : A Program in Python for Decorators
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 12:14 hrs
Version : 1.0
/*************************************
## Program Description : Program for Decorators in Python
## Python Development Environment & Runtime - Python, Anaconda
def vAR_CSLAB_inc(vAR_x):
return vAR_x + 1
def vAR_CSLAB_dec(vAR_x):
return vAR_x - 1
def vAR_CSLAB_operate(func, vAR_x):
vAR_result = func(vAR_x)
return vAR_result
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DECORATORS_AS_FUNCTIONS_V1
Purpose : A Program in Python for Decorators as Functions
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 12:28 hrs
Version : 1.0
/*************************************
## Program Description : Program for Decorators as Functions in Python
## Python Development Environment & Runtime - Python, Anaconda
def vAR_replacing_decorator_with_args(arg):
print("defining the decorator")
def vAR_decorator(function):
# in this inner function, arg is available too
print("doing decoration, %r" % arg)
def vAR_wrapper(*args, **kwargs):
print("inside wrapper, %r %r" % (args, kwargs))
return function(*args, **kwargs)
return vAR_wrapper
return vAR_decorator
@replacing_decorator_with_args("abc")
def vAR_function(*args, **kwargs):
print("inside function, %r %r" % (args, kwargs))
return 14
vAR_function(11, 12)
function(11, 12)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DECORATORS_AS_CLASSES_V1
Purpose : A Program in Python for Decorators as Classes
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 12:41 hrs
Version : 1.0
/*************************************
## Program Description : Program for Decorators as Functions in Python
## Python Development Environment & Runtime - Python, Anaconda
class vAR_decorator_class(object):
def __init__(self, arg):
# this method is called in the decorator expression
print("in decorator init, %s" % arg)
self.arg = arg
def __call__(self, function):
# this method is called to do the job
print("in decorator call, %s" % self.arg)
return function
vAR_deco_instance = vAR_decorator_class('foo')
@deco_instance
def vAR_function(*args, **kwargs):
print("in function, %s %s" % (args, kwargs))
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_DECORATORS_COPYING_DOCSTRING_OTHER_ATTRIBUTES_V1
Purpose : A Program in Python for Decorators - Copying the docstring and other attributes of the original function
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 12:55 hrs
Version : 1.0
/*************************************
## Program Description : Program for Copying the docstring and other attributes of the original function in Python
## Python Development Environment & Runtime - Python, Anaconda
import functools
def vAR_replacing_decorator_with_args(arg):
print("defining the decorator")
def vAR_decorator(function):
print("doing decoration, %r" % arg)
def vAR_wrapper(*args, **kwargs):
print("inside wrapper, %r %r" % (args, kwargs))
return function(*args, **kwargs)
return functools.update_wrapper(_wrapper, function)
return vAR_decorator
@replacing_decorator_with_args("abc")
def vAR_function():
"extensive documentation"
print("inside function")
return 14
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/**************************************
File Name : CSLAB_EXAMPLE_STANDARD_LIBRARY_V1
Purpose : A Program in Python for Example of Standard Library
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 14:00 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Example of Standard Library in Python
## Python Development Environment & Runtime - Python, Anaconda
import os
import platform
import logging
if platform.platform().startswith('Windows'):
vAR_CSLAB_logging_file = os.path.join(os.getenv('HOMEDRIVE'),
os.getenv('HOMEPATH'),
'test.log')
else:
vAR_CSLAB_logging_file = os.path.join(os.getenv('HOME'),
'test.log')
print("Logging to", vAR_CSLAB_logging_file)
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s : %(levelname)s : %(message)s',
filename=vAR_CSLAB_logging_file,
filemode='w',
)
logging.debug("Start of the program")
logging.info("Doing something")
logging.warning("Dying now")
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_DEPRICIATION_OF_FUNCTIONS_V1
Purpose : A Program in Python for Depriciation of Functions
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 14:21 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Depriciation of Functions in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_CSLAB_BV=5000
vAR_CSLAB_Life=5
vAR_CSLAB_slvg=200
def Depreciation_Function():
print ('%15s'%"Year"'%15s'%"Dep"'%15s'% "BV")
for i in range(0,vAR_CSLAB_Life):
Dep=((vAR_CSLAB_BV-vAR_CSLAB_slvg)*i)/vAR_CSLAB_Life
AccDep=((vAR_CSLAB_BV-vAR_CSLAB_slvg)*(vAR_CSLAB_Life-i))/vAR_CSLAB_Life
print ('%12.0f'%i,'%12.2f'%Dep, '%12.2f'%AccDep)
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/*********************************
File Name : CSLAB_WHILE_LOOP_REMOVING_DECORATOR_V1
Purpose : A Program in Python for While Loop Removing Decorator
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 14:42 hrs
Version : 1.0
/*************************************
## Program Description : Program for While Loop Removing Decorator in Python
## Python Development Environment & Runtime - Python, Anaconda
def vAR_find_answers():
vAR_answers = []
while True:
vAR_ans = look_for_next_answer()
if vAR_ans is None:
break
answers.append(vAR_ans)
return answers
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_PLUGIN_REGISTRATION_SYSTEM_V1
Purpose : A Program in Python for Plugin Registartion System
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 15:05 hrs
Version : 1.0
/*************************************
## Program Description : Program for Plugin Registartion System in Python
## Python Development Environment & Runtime - Python, Anaconda
class vAR_WordProcessor(object):
vAR_PLUGINS = []
def vAR_process(self, text):
for plugin in self.PLUGINS:
vAR_text = plugin().cleanup(text)
return vAR_text
@classmethod
def vAR_plugin(cls, plugin):
cls.vAR_PLUGINS.append(plugin)
@WordProcessor.plugin
class vAR_CleanMdashesExtension(object):
def vAR_cleanup(self, text):
return vAR_text.replace('—', u'N{em dash}')
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_CONTEXT_MANAGERS_V1
Purpose : A Program in Python for Context Mangers
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 15:28 hrs
Version : 1.0
/*************************************
## Program Description : Program for Context Mangers in Python
## Python Development Environment & Runtime - Python, Anaconda
class vAR_closing(object):
def __init__(self, obj):
self.obj = obj
def __enter__(self):
return self.obj
def __exit__(self, *args):
self.obj.close()
#with closing(open('/C:/Python_Programs/Train_Data_Unplanned_Expenses.xlsx', 'w')) as f:
#f.write('the contentsn')
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_CONTEXT_MANAGERS_CATCHING_EXCEPTIONS_V1
Purpose : A Program in Python for Context Mangers - Catching Exceptions
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 15:47 hrs
Version : 1.0
/*************************************
## Program Description : Program for Context Mangers - Catching Exceptions in Python
## Python Development Environment & Runtime - Python, Anaconda
class vAR_assert_raises(object):
# based on pytest and unittest.TestCase
def __init__(self, type):
self.type = type
def __enter__(self):
pass
def __exit__(self, type, value, traceback):
if type is None:
raise AssertionError('exception expected')
if issubclass(type, self.type):
return True # swallow the expected exception
raise AssertionError('wrong exception type')
with assert_raises(KeyError):
{}['foo']
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_CONTEXT_MANAGERS_DEFINING_USING_GENERATORS_V1
Purpose : A Program in Python for Defining Context Mangers using Generators
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 16:14 hrs
Version : 1.0
/*************************************
## Program Description : Program for Defining Context Mangers using Generators in Python
## Python Development Environment & Runtime - Python, Anaconda
@contextlib.contextmanager
def vAR_some_generator(<arguments>):
<setup>
try:
yield <value>
finally:
<cleanup>
@contextlib.contextmanager
def vAR_closing(obj):
try:
yield obj
finally:
obj.close()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_NDARRAY_V1
Purpose : A Program in Python for ndarray
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 16:38 hrs
Version : 1.0
/*************************************
## Program Description : Program for for ndarray in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
vAR_CSLAB_ndarray = vAR_np.ndarray(shape=(2,2), dtype=float, order='F')
vAR_CSLAB_ndarray = vAR_np.ndarray((2,), buffer=np.array([1,2,3]),offset=np.int_().itemsize,dtype=int)
vAR_CSLAB_ndarray
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_NDARRAY_BLOCK_OF_MEMORY_V1
Purpose : A Program in Python for ndarray - Block of Memory
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 16:38 hrs
Version : 1.0
/*************************************
## Program Description : Program for for ndarray - Block of Memory in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
vAR_CSLAB_X = vAR_np.array([1, 2, 3], dtype=np.int32)
vAR_CSLAB_X.data
bytes(vAR_CSLAB_X.data)
vAR_CSLAB_X.__array_interface__['data'][0]
vAR_CSLAB_X.__array_interface__
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_NDARRAY_DATA_TYPE_V1
Purpose : A Program in Python for ndarray - Data Type
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 16:47 hrs
Version : 1.0
/*************************************
## Program Description : Program for ndarray - Data Type in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
vAR_CSLAB_X = vAR_np.array([1, 2, 3])
vAR_CSLAB_X.dtype
vAR_np.dtype(int).itemsize
vAR_np.dtype(int).byteorder
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_NDARRAY_INDEXING_SCHEME_STRIDES_V1
Purpose : A Program in Python for ndarray - Indexing Scheme Strides
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 17:05 hrs
Version : 1.0
/*************************************
## Program Description : Program for ndarray - Indexing Scheme Strides in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
vAR_CSLAB_X = vAR_np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]], dtype=np.int8)
str(vAR_CSLAB_X.data)
vAR_CSLAB_X.strides
vAR_CSLAB_byte_offset = 3*1 + 1*2
vAR_CSLAB_X.flat[CSLAB_byte_offset]
vAR_CSLAB_X[1, 2]
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_NDARRAY_SLICING_WITH_INTEGERS_V1
Purpose : A Program in Python for ndarray - Slicing With Integers
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 17:18 hrs
Version : 1.0
/*************************************
## Program Description : Program for ndarray - Slicing With Integers in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
vAR_CSLAB_X = vAR_np.array([1, 2, 3, 4, 5, 6], dtype=np.int32)
vAR_CSLAB_y = x[::-1]
vAR_CSLAB_y.strides
vAR_CSLAB_y = x[2:]
vAR_CSLAB_y
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_NDARRAY_TRANSPOSING_WITH_INTEGERS_V1
Purpose : A Program in Python for ndarray - Transposing With Integers
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 17:31 hrs
Version : 1.0
/*************************************
## Program Description : Program for ndarray - Transposing With Integers in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
vAR_CSLAB_X = vAR_np.array([1, 2, 3, 4, 5, 6], dtype=np.int32)
vAR_CSLAB_y = vAR_CSLAB_x[::-1]
VAR_CSLAB_y.strides
vAR_CSLAB_y = vAR_CSLAB_x[2:]
vAR_CSLAB_y
vAR_CSLAB_Z = vAR_np.zeros((10, 10, 10), dtype=np.float)
vAR_CSLAB_Z.strides
vAR_CSLAB_Z[::2,::3,::4].strides
vAR_CSLAB_A = np.zeros((10, 10, 10), dtype=np.float)
vAR_CSLAB_A.T.strides
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_NDARRAY_RESHAPING_INTEGERS_V1
Purpose : A Program in Python for ndarray - Reshaping Integers
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 17:47 hrs
Version : 1.0
/*************************************
## Program Description : Program for ndarray - Reshaping Integers in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
vAR_CSLAB_X = vAR_np.array([1, 2, 3, 4, 5, 6], dtype=np.int32)
vAR_CSLAB_y = vAR_CSLAB_X[::-1]
vAR_CSLAB_y.strides
vAR_CSLAB_y = vAR_CSLAB_X[2:]
vAR_CSLAB_y
vAR_CSLAB_Z = vAR_np.zeros((10, 10, 10), dtype=np.float)
vAR_CSLAB_Z.strides
vAR_CSLAB_Z[::2,::3,::4].strides
vAR_CSLAB_A = vAR_np.arange(6, dtype=np.int8).reshape(3, 2)
vAR_CSLAB_A
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_NDARRAY_BROADCASTING_V1
Purpose : A Program in Python for ndarray - Broadcasing
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 18:03 hrs
Version : 1.0
/*************************************
## Program Description : Program for ndarray - Broadcasing in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
from numpy.lib.stride_tricks import as_strided
vAR_CSLAB_X = np.array([1, 2, 3, 4], dtype=np.int16)
vAR_CSLAB_X2 = as_strided(vAR_CSLAB_X, strides=(0, 1*2), shape=(3, 4))
vAR_CSLAB_Y = vAR_np.array([5, 6, 7], dtype=np.int16)
vAR_CSLAB_Y2 = as_strided(vAR_CSLAB_Y, strides=(1*2, 0), shape=(3, 4))
vAR_CSLAB_X2 * vAR_CSLAB_Y2
vAR_CSLAB_X = vAR_np.array([1, 2, 3, 4], dtype=np.int16)
vAR_CSLAB_Y = vAR_np.array([5, 6, 7], dtype=np.int16)
vAR_CSLAB_X[vAR_np.newaxis,:] * vAR_CSLAB_Y[:,vAR_np.newaxis]
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/**************************************
File Name : CSLAB_NDARRAY_UNIVERSAL_FUNCTION_V1
Purpose : A Program in Python for Universal Function on ndarray
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 18:24 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Universal Function on ndarray in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
vAR_np.random.seed(0)
def vAR_CSLAB_compute_reciprocals(vAR_CSLAB_values):
vAR_CSLAB_output = vAR_np.empty(len(vAR_CSLAB_values))
for i in range(len(vAR_CSLAB_values)):
vAR_CSLAB_output[i] = 1.0 / vAR_CSLAB_values[i]
return vAR_CSLAB_output
vAR_CSLAB_values = vAR_np.random.randint(1, 10, size=5)
vAR_CSLAB_compute_reciprocals(vAR_CSLAB_values)
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/*********************************
File Name : CSLAB_NDARRAY_GENERALIZED_UNIVERSAL_FUNCTION_V1
Purpose : A Program in Python for ndarray - Generalized Universal Function
Author : DeepSphere.AI, Inc.
Date and Time : 18/12/2018 19:02 hrs
Version : 1.0
/*************************************
## Program Description : Program for ndarray - Universal Function in Python
## Python Development Environment & Runtime - Python, Anaconda
void gufunc_loop(void **args, int *dimensions, int *steps, void *data)
{
char *input_1 = (char*)args[0]; /* these are as previously */
char *input_2 = (char*)args[1];
char *output = (char*)args[2];
int input_1_stride_m = steps[3]; /* strides for the core dimensions */
int input_1_stride_n = steps[4]; /* are added after the non-core */
int input_2_strides_n = steps[5]; /* steps */
int input_2_strides_p = steps[6];
int output_strides_n = steps[7];
int output_strides_p = steps[8];
int m = dimension[1]; /* core dimensions are added after */
int n = dimension[2]; /* the main dimension; order as in */
int p = dimension[3]; /* signature */
int i;
for (i = 0; i < dimensions[0]; ++i) {
matmul_for_strided_matrices(input_1, input_2, output,
strides for each array...);
input_1 += steps[0];
input_2 += steps[1];
output += steps[2];
}
}
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_NDARRAY_OLD_BUFFER_PROTOCOL_V1
Purpose : A Program in Python for ndarray - Old Buffer Protocol
Author : DeepSphere.AI, Inc.
Date and Time : 19/12/2018 9:51 hrs
Version : 1.0
/*************************************
## Program Description : Program for ndarray - Old Buffer Protocol in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
from PIL import Image
vAR_CSLAB_data = vAR_np.zeros((200, 200, 4), dtype=np.int8)
vAR_CSLAB_data[:, :] = [255, 0, 0, 255] # Red
vAR_CSLAB_data = vAR_CSLAB_data.view(np.int32).squeeze()
vAR_CSLAB_img = Image.frombuffer("RGBA", (200, 200), data, "raw", "RGBA", 0, 1)
vAR_CSLAB_img.save('test.png')
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_IMAGE_PROCESSING_OPENING_WRITING_TO_IMAGE_V1
Purpose : A Program in Python for Opening & Writing to Image Files
Author : DeepSphere.AI, Inc.
Date and Time : 19/12/2018 10:32 hrs
Version : 1.0
/*************************************
## Program Description : Program for Opening & Writing to Image Files in Python
## Python Development Environment & Runtime - Python, Anaconda
from scipy import misc
vAR_CSLAB_f = misc.face()
misc.imsave('face.png', vAR_CSLAB_f) # uses the Image module (PIL)
import matplotlib.pyplot as vAR_plt
vAR_plt.imshow(vAR_CSLAB_f)
vAR_plt.show()
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_IMAGE_PROCESSING_DISPLAYING_IMAGES_V1
Purpose : A Program in Python for Displaying Images
Author : DeepSphere.AI, Inc.
Date and Time : 19/12/2018 11:25 hrs
Version : 1.0
/*************************************
## Program Description : Program for Displaying Images in Python
## Python Development Environment & Runtime - Python, Anaconda
vAR_CSLAB_f = misc.face(gray=True)
import matplotlib.pyplot as vAR_plt
vAR_plt.imshow(vAR_CSLAB_f, cmap=vAR_plt.cm.gray)
vAR_plt.imshow(vAR_CSLAB_f, cmap=vAR_plt.cm.gray, vmin=30, vmax=200)
vAR_plt.axis('off')
vAR_plt.contour(vAR_CSLAB_f, [50, 200])
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_IMAGE_PROCESSING_DISPLAYING_IMAGES_BASIC_MANIPULATION_V1
Purpose : A Program in Python for Image Processing - Basic Manipulation
Author : DeepSphere.AI, Inc.
Date and Time : 19/12/2018 11:25 hrs
Version : 1.0
/*************************************
## Program Description : Program for for Image Processing - Basic Manipulation in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
vAR_CSLAB_face = misc.face(gray=True)
vAR_CSLAB_face[0, 40]
vAR_CSLAB_face[10:13, 20:23]
vAR_CSLAB_face[100:120] = 255
vAR_lx, vAR_ly = vAR_CSLAB_face.shape
vAR_X, vAR_Y = vAR_np.ogrid[0:vAR_lx, 0:vAR_ly]
vAR_CSLAB_mask = (vAR_X - vAR_lx / 2) ** 2 + (vAR_Y - vAR_ly / 2) ** 2 > vAR_lx * vAR_ly / 4
vAR_CSLAB_face[vAR_CSLAB_mask] = 0
vAR_CSLAB_face[range(400), range(400)] = 255
vAR_plt.imshow(CSLAB_face)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_IMAGE_PROCESSING_GEOMETRICAL_TRANSFORMATIONS_V1
Purpose : A Program in Python for Image Processing - Geometrical Transformations
Author : DeepSphere.AI, Inc.
Date and Time : 19/12/2018 11:44 hrs
Version : 1.0
/*************************************
## Program Description : Program for Image Processing - Geometrical Transformations in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
from scipy import ndimage
vAR_CSLAB_face = misc.face(gray=True)
vAR_lx, vAR_ly = vAR_CSLAB_face.shape
vAR_crop_face = vAR_CSLAB_face[vAR_lx // 4: - vAR_lx // 4, vAR_ly // 4: - vAR_ly // 4]
vAR_CSLAB_flip_ud_face = vAR_np.flipud(vAR_CSLAB_face)
vAR_CSLAB_rotate_face = ndimage.rotate(vAR_CSLAB_face, 45)
vAR_CSLAB_rotate_face_noreshape = ndimage.rotate(vAR_CSLAB_face, 45, reshape=False)
vAR_plt.imshow(vAR_CSLAB_flip_ud_face)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_IMAGE_PROCESSING_FILTERING_BLURRING_V1
Purpose : A Program in Python for Image Processing - Blurring
Author : DeepSphere.AI, Inc.
Date and Time : 19/12/2018 12:07 hrs
Version : 1.0
/*************************************
## Program Description : Program for Image Processing - Blurring in Python
## Python Development Environment & Runtime - Python, Anaconda
from scipy import misc
from scipy import ndimage
vAR_CSLAB_face = misc.face(gray=True)
vAR_CSLAB_blurred_face = ndimage.gaussian_filter(vAR_CSLAB_face, sigma=3)
vAR_CSLAB_very_blurred = ndimage.gaussian_filter(vAR_CSLAB_face, sigma=5)
vAR_plt.imshow(vAR_CSLAB_very_blurred)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_IMAGE_PROCESSING_FILTERING_SHARPENING_V1
Purpose : A Program in Python for Image Processing - Sharpeneing
Author : DeepSphere.AI, Inc.
Date and Time : 19/12/2018 12:34 hrs
Version : 1.0
/*************************************
## Program Description : Program for Image Processing - Blurring in Python
## Python Development Environment & Runtime - Python, Anaconda
from scipy import misc
from scipy import ndimage
vAR_CSLAB_face = misc.face(gray=True).astype(float)
vAR_CSLAB_blurred_f = ndimage.gaussian_filter(vAR_CSLAB_face, 3)
vAR_plt.imshow(vAR_CSLAB_very_blurred)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_IMAGE_PROCESSING_FILTERING_DENOISING_V1
Purpose : A Program in Python for Image Processing - Denoising
Author : DeepSphere.AI, Inc.
Date and Time : 19/12/2018 12:53 hrs
Version : 1.0
/*************************************
## Program Description : Program for Image Processing - Denoising in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
from scipy import misc
vAR_CSLAB_f = misc.face(gray=True)
vAR_CSLAB_f = vAR_CSLAB_f[230:290, 220:320]
vAR_CSLAB_noisy = vAR_CSLAB_f + 0.4 * vAR_CSLAB_f.std() * vAR_np.random.random(CSLAB_f.shape)
vAR_plt.imshow(vAR_CSLAB_noisy)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_IMAGE_PROCESSING_FILTERING_APPLY_GAUSSIAN_FILTER_V1
Purpose : A Program in Python for Image Processing - Applying Gaussian Filter
Author : DeepSphere.AI, Inc.
Date and Time : 19/12/2018 13:42 hrs
Version : 1.0
/*************************************
## Program Description : Program for Image Processing - Applying Gaussian Filter in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
from scipy import ndimage
import matplotlib.pyplot as vAR_plt
from scipy import misc
vAR_CSLAB_f = misc.face(gray=True)
vAR_CSLAB_f = vAR_CSLAB_f[230:290, 220:320]
vAR_CSLAB_noisy = vAR_CSLAB_f + 0.4 * vAR_CSLAB_f.std() * vAR_np.random.random(vAR_CSLAB_f.shape)
vAR_CSLAB_gauss_denoised = ndimage.gaussian_filter(vAR_CSLAB_noisy, 2)
vAR_plt.imshow(vAR_CSLAB_gauss_denoised)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_IMAGE_PROCESSING_FILTERING_APPLY_MEDIAN_FILTER_V1
Purpose : A Program in Python for Image Processing - Applying Median Filter
Author : DeepSphere.AI, Inc.
Date and Time : 19/12/2018 14:08 hrs
Version : 1.0
/*************************************
## Program Description : Program for Image Processing - Applying Median Filter in Python
## Python Development Environment & Runtime - Python, Anaconda
import numpy as vAR_np
from scipy import ndimage
import matplotlib.pyplot as vAR_plt
from scipy import misc
vAR_CSLAB_f = misc.face(gray=True)
vAR_CSLAB_f = vAR_CSLAB_f[230:290, 220:320]
vAR_CSLAB_noisy = vAR_CSLAB_f + 0.4 * vAR_CSLAB_f.std() * vAR_np.random.random(vAR_CSLAB_f.shape)
vAR_CSLAB_med_denoised = ndimage.median_filter(vAR_CSLAB_noisy, 3)
vAR_plt.imshow(CSLAB_med_denoised)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_IMAGE_PROCESSING_FEATURE_EXTRACTION_EDGE_DETECTION_V1
Purpose : A Program in Python for Image Processing - Edge Detection
Author : DeepSphere.AI, Inc.
Date and Time : 19/12/2018 14:22 hrs
Version : 1.0
/*************************************
## Program Description : Program for Image Processing - Edge Detection in Python
## Python Development Environment & Runtime - Python, Anaconda
from scipy import misc
import numpy as vAR_np
import numpy as vAR_np
from scipy import ndimage
import matplotlib.pyplot as vAR_plt
import matplotlib.pyplot as vAR_plt
vAR_CSLAB_im = vAR_np.zeros((256, 256))
vAR_CSLAB_im[64:-64, 64:-64] = 1
CSLAB_im = ndimage.rotate(CSLAB_im, 15, mode='constant')
CSLAB_im = ndimage.gaussian_filter(CSLAB_im, 8)
plt.imshow(CSLAB_im)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/*********************************
File Name : CSLAB_IMAGE_PROCESSING_FEATURE_EXTRACTION_SEGMENTATION_V1
Purpose : A Program in Python for Image Processing - Segmentation
Author : DeepSphere.AI, Inc.
Date and Time : 19/12/2018 14:38 hrs
Version : 1.0
## Program Description : Program for Image Processing - Edge Detection in Python
## Python Development Environment & Runtime - Python, Anaconda
from scipy import misc
import numpy as vAR_np
from scipy import ndimage
import matplotlib.pyplot as vAR_plt
vAR_CSLAB_n = 10
vAR_CSLAB_l = 256
vAR_CSLAB_im = vAR_np.zeros((CSLAB_l, CSLAB_l))
vAR_np.random.seed(1)
vAR_CSLAB_points = vAR_CSLAB_l*vAR_np.random.random((2, vAR_CSLAB_n**2))
vAR_CSLAB_im[(vAR_CSLAB_points[0]).astype(vAR_np.int), (vAR_CSLAB_points[1]).astype(vAR_np.int)] = 1
vAR_CSLAB_im = ndimage.gaussian_filter(vAR_CSLAB_im, sigma=vAR_CSLAB_l/(4.*vAR_CSLAB_n))
vAR_plt.imshow(vAR_CSLAB_im)
/*******************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*******************************
/**************************************
File Name : CSLAB_TENSORFLOW_HELLO_WORLD_V1
Purpose : A Program in Python Tensorflow for Basic Hello World
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 9:38 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Basic Hello World using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as tf
vAR_CSLAB_hello = tf.constant('Hello, TensorFlow!')
# Start tf session
VAR_CSLAB_sess = tf.Session()
# Run the operation of initializing the constant
print(VAR_CSLAB_sess.run(vAR_CSLAB_hello))
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_TENSORS_V1
Purpose : A Program in Python Tensorflow for Tensors
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 9:47 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Tensors using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
vAR_CSLAB_C = vAR_tf.constant([[1.0, 2.0], [3.0, 4.0]])
vAR_CSLAB_D = vAR_tf.constant([[1.0, 1.0], [0.0, 1.0]])
# Construct a `Session` to execute the graph.
vAR_CSLAB_sess = vAR_tf.Session()
vAR_CSLAB_E = vAR_tf.matmul(vAR_CSLAB_C, vAR_CSLAB_D)
# Execute the graph and store the value that `e` represents in `result`.
vAR_CSLAB_result = vAR_CSLAB_sess.run(vAR_CSLAB_E)
vAR_CSLAB_result
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_FIXED_TENSORS_V1
Purpose : A Program in Python Tensorflow for Fixed Tensors
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 9:58 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Fixed Tensors using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
VAR_CSLAB_zero_tsr = tf.zeros([4,5])
vAR_CSLAB_sess = vAR_tf.Session()
vAR_CSLAB_result = vAR_CSLAB_sess.run(VAR_CSLAB_zero_tsr)
vAR_CSLAB_result
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_SEQUENCE_TENSORS_V1
Purpose : A Program in Python Tensorflow for Sequence Tensors
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 10:12 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Sequence Tensors using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
VAR_CSLAB_linear_tsr = tf.linspace(start=0.0, stop=1.0, num=3)
vAR_CSLAB_sess = vAR_tf.Session()
vAR_CSLAB_result = vAR_CSLAB_sess.run(VAR_CSLAB_linear_tsr)
vAR_CSLAB_result
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_RANDON_TENSORS_V1
Purpose : A Program in Python Tensorflow for Random Tensors
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 10:29 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Random Tensors using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
vAR_CSLAB_rand_tsr = tf.random_uniform([3,4],minval=0,maxval=1)
vAR_CSLAB_sess = vAR_tf.Session()
vAR_CSLAB_result = vAR_CSLAB_sess.run(vAR_CSLAB_rand_tsr)
vAR_CSLAB_result
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_CONSTANTS_V1
Purpose : A Program in Python Tensorflow for Constants
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 10:37 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Constants using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
vAR_CSLAB_C = vAR_tf.constant([[1.0, 2.0], [3.0, 4.0]])
vAR_CSLAB_D = vAR_tf.constant([[1.0, 1.0], [0.0, 1.0]])
vAR_CSLAB_sess = vAR_tf.Session()
print(vAR_CSLAB_sess.run(vAR_CSLAB_C))
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_VARIABLES_V1
Purpose : A Program in Python Tensorflow for Variables
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 10:48 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Variables using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
vAR_CSLAB_my_var = vAR_tf.Variable(tf.zeros([2,3]))
vAR_CSLAB_my_var
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_PLACEHOLDERS_V1
Purpose : A Program in Python Tensorflow for Placeholders
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 10:59 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Placeholders using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
import numpy as vAR_np
vAR_CSLAB_X = vAR_tf.placeholder(tf.float32, shape=[2,2])
vAR_CSLAB_Y = vAR_tf.identity(vAR_CSLAB_X)
vAR_CSLAB_X_VALS = vAR_np.random.rand(2,2)
vAR_CSLAB_sess = vAR_tf.Session()
vAR_CSLAB_sess.run(vAR_CSLAB_Y, feed_dict={vAR_CSLAB_X:vAR_CSLAB_X_VALS})
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_GRAPHS_V1
Purpose : A Program in Python Tensorflow for Graphs
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 11:14 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Graphs using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
vAR_CSLAB_g = vAR_tf.Graph()
with vAR_CSLAB_g.as_default():
VAR_CSLAB_A = vAR_tf.constant(15, name="input_a")
VAR_CSLAB_B = vAR_tf.constant(13, name="input_b")
VAR_CSLAB_C = vAR_tf.add(VAR_CSLAB_A,VAR_CSLAB_B)
vAR_CSLAB_sess = vAR_tf.Session(graph=vAR_CSLAB_g)
vAR_CSLAB_sess
print(vAR_CSLAB_C)
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_SESSION_V1
Purpose : A Program in Python Tensorflow for Sessions
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 11:28 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Sessions using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
vAR_CSLAB_C = vAR_tf.constant([[1.0, 2.0], [3.0, 4.0]])
vAR_CSLAB_D = vAR_tf.constant([[1.0, 1.0], [0.0, 1.0]])
vAR_CSLAB_sess = vAR_tf.Session()
vAR_CSLAB_E = vAR_tf.matmul(vAR_CSLAB_C, vAR_CSLAB_D)
print(vAR_CSLAB_sess.run(vAR_CSLAB_E))
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_FEED_DICTIONARY_V1
Purpose : A Program in Python Tensorflow for Feed Dictionary
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 11:43 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Feed Dictionary using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
import numpy as vAR_np
vAR_CSLAB_X = vAR_tf.placeholder(tf.float32, shape=[2,2])
vAR_CSLAB_Y = vAR_tf.identity(vAR_CSLAB_X)
vAR_CSLAB_X_VALS = vAR_np.random.rand(2,2)
vAR_CSLAB_sess = vAR_tf.Session()
vAR_CSLAB_sess.run(vAR_CSLAB_Y, feed_dict={vAR_CSLAB_X:vAR_CSLAB_X_VALS})
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_DATA_TYPE_V1
Purpose : A Program in Python Tensorflow for Data Types
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 11:51 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Data Types using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
import numpy as vAR_np
vAR_CSLAB_X = vAR_tf.placeholder(dtype = tf.float32, shape=[2,2])
vAR_CSLAB_X.dtype
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_ADD_TWO_CONSATNTS_V1
Purpose : A Program in Python Tensorflow for Adding Two Constants
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 12:04 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Adding Two Constants using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
vAR_CSLAB_C = vAR_tf.constant([[1.0, 2.0], [3.0, 4.0]])
vAR_CSLAB_D = vAR_tf.constant([[1.0, 1.0], [0.0, 1.0]])
vAR_CSLAB_sess = vAR_tf.Session()
vAR_CSLAB_E = vAR_tf.add(vAR_CSLAB_C,vAR_CSLAB_D)
print(vAR_CSLAB_sess.run(vAR_CSLAB_E))
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************
/**************************************
File Name : CSLAB_TENSORFLOW_MULTIPLY_TWO_CONSATNTS_V1
Purpose : A Program in Python Tensorflow for Multiplying Two Constants
Author : DeepSphere.AI, Inc.
Date and Time : 21/12/2018 12:17 hrs
Version : 1.0
/***********************************************
## Program Description : Program for Multiplying Two Constants using Tensorflow in Python
## Python Development Environment & Runtime - Python, Anaconda, Tensorflow, Tensorboard
import tensorflow as vAR_tf
vAR_CSLAB_C = vAR_tf.constant([[1.0, 2.0], [3.0, 4.0]])
vAR_CSLAB_D = vAR_tf.constant([[1.0, 1.0], [0.0, 1.0]])
vAR_CSLAB_sess = vAR_tf.Session()
vAR_CSLAB_E = vAR_tf.matmul(vAR_CSLAB_C,vAR_CSLAB_D)
print(vAR_CSLAB_sess.run(vAR_CSLAB_E))
/*********************************************
Disclaimer:
We are providing this code block strictly for learning and researching. This is not a production-ready code. We assume no liability for this code under any circumstance. By using this code, users assume full risk. All software, hardware, and other products that are referenced in these materials, belong to the respective vendor who developed or who owns this product.
/*********************************************