Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Topological_Machine_Learning
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Colbry, Dirk
Topological_Machine_Learning
Commits
2dfa2482
Commit
2dfa2482
authored
4 years ago
by
shawk masboob
Browse files
Options
Downloads
Patches
Plain Diff
linted code
parent
ee0d5356
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Topological_ML/tda_function.py
+49
-0
49 additions, 0 deletions
Topological_ML/tda_function.py
with
49 additions
and
0 deletions
Topological_ML/tda_function.py
0 → 100644
+
49
−
0
View file @
2dfa2482
import
sklearn
from
sklearn.linear_model
import
LinearRegression
import
kmapper
as
km
import
pandas
as
pd
import
numpy
as
np
def
numpy_to_pandas
(
sklearn_data
):
"""
Converts scikit-learn numpy data into pandas dataframe.
Input: name of dataframe
Output: pandas dataframe
"""
data
=
pd
.
DataFrame
(
data
=
sklearn_data
.
data
,
columns
=
sklearn_data
.
feature_names
)
data
[
'
target
'
]
=
pd
.
Series
(
sklearn_data
.
target
)
return
data
def
linear_regression
(
feature
,
predictor
):
"""
Ordinary least squares Linear Regression.
input: x = independent variables
y = dependent variable
output: R^2
"""
model
=
LinearRegression
()
model
.
fit
(
feature
,
predictor
)
return
model
.
score
(
feature
,
predictor
)
def
lens_1d
(
features
,
random_num
,
verbosity
):
"""
input:
output:
"""
model
=
sklearn
.
ensemble
.
IsolationForest
(
random_state
=
random_num
)
model
.
fit
(
features
)
lens1
=
model
.
decision_function
(
features
).
reshape
((
features
.
shape
[
0
],
1
))
mapper
=
km
.
KeplerMapper
(
verbose
=
verbosity
)
lens2
=
mapper
.
fit_transform
(
features
,
projection
=
"
l2norm
"
)
lens
=
np
.
c_
[
lens1
,
lens2
]
return
lens
def
county_crosstab
(
data
,
county
,
year
,
index
,
columns
):
"""
input:
output:
"""
subset_df
=
data
[
data
.
year
==
year
]
sub_df
=
subset_df
[
subset_df
.
county
==
county
]
crosstab
=
pd
.
crosstab
(
index
=
sub_df
[
index
],
columns
=
sub_df
[
columns
])
return
crosstab
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment