Skip to content

Instantly share code, notes, and snippets.

View dapostolopoylos's full-sized avatar

Dimitris Apostolopoulos dapostolopoylos

View GitHub Profile
@dapostolopoylos
dapostolopoylos / R_Squared.py
Created December 10, 2021 09:16
How well does my data fit in a polynomial regression?
# It is important to know how well the relationship between the values of the x- and y-axis is, if there are no relationship
# the polynomial regression can not be used to predict anything.
#
# The relationship is measured with a value called the r-squared.
# The r-squared value ranges from 0 to 1, where 0 means no relationship, and 1 means 100% related.
import numpy
from sklearn.metrics import r2_score
x = [1,2,3,5,6,7,8,9,10,12,13,14,15,16,18,19,21,22]
@dapostolopoylos
dapostolopoylos / PolynomialRegressionExample.py
Created December 10, 2021 09:11
Basic Polynomial Regression example
import numpy
import matplotlib.pyplot as plt
x = [1,2,3,5,6,7,8,9,10,12,13,14,15,16,18,19,21,22]
y = [100,90,80,60,60,55,60,65,70,70,75,76,78,79,90,99,99,100]
mymodel = numpy.poly1d(numpy.polyfit(x, y, 3))
myline = numpy.linspace(1, 22, 100)
@dapostolopoylos
dapostolopoylos / PredictSpeedWithLinRegression.py
Created December 10, 2021 08:59
Predict the speed of a 10 years old car using linear regression
# the x-axis represents car's age, and the y-axis represents car's speed
from scipy import stats
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
slope, intercept, r, p, std_err = stats.linregress(x, y)
def myfunc(x):
return slope * x + intercept
@dapostolopoylos
dapostolopoylos / LinearRegressionExmple.py
Last active December 10, 2021 09:03
Basic Linear Regression example
# This relationship - the coefficient of correlation - is called r.
# The r value ranges from -1 to 1, where 0 means no relationship, and 1 (and -1) means 100% related.
import matplotlib.pyplot as plt
from scipy import stats
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]
slope, intercept, r, p, std_err = stats.linregress(x, y)
@dapostolopoylos
dapostolopoylos / StyleKiller.vba
Last active December 9, 2019 15:45
Deletes all styles in an Excel file except from the built in
'Credit to: https://superuser.com/questions/1291085/delete-all-custom-cell-styles-excel
Sub StyleKiller()
Dim N As Long, i As Long
With ActiveWorkbook
N = .Styles.Count
For i = N To 1 Step -1
If Not .Styles(i).BuiltIn Then .Styles(i).Delete
Next i
@dapostolopoylos
dapostolopoylos / searchValueInDB.sql
Last active May 6, 2019 06:37
Search a value anywhere in the Database
DECLARE @SearchStr nvarchar(100)
SET @SearchStr = '## YOUR STRING HERE ##'
-- Copyright © 2002 Narayana Vyas Kondreddi. All rights reserved.
-- Purpose: To search all columns of all tables for a given search string
-- Written by: Narayana Vyas Kondreddi
-- Site: http://vyaskn.tripod.com
-- Updated and tested by Tim Gaunt
-- http://www.thesitedoctor.co.uk
@dapostolopoylos
dapostolopoylos / loopThroughFiles.qvs
Created April 9, 2019 14:26
A Qlikview script that uses some usefull techniques for folder/files manipulation
SET vPath = '\\servername\folder1\subfolder1';
//Load all sub folders names.
//Each folder name includes the corresponding year in its name (last 4 characters)
sub DoDir (Root)
for each Dir in DirList (Root&'\*' )
tmp:
LOAD
'$(Dir)' as Dir,
Right('$(Dir)',4) as Year
@dapostolopoylos
dapostolopoylos / Top20.qvs
Last active March 8, 2017 15:27
Top 20 materials by revenue
=aggr(if(Rank(Sum(Revenue))<=20,Material),Material)
@dapostolopoylos
dapostolopoylos / openQvwWithoutData.bat
Last active November 23, 2016 11:52
Batch file that is used to open a Qlik View application without data
start "" "C:\Program Files\QlikView\qv.exe" /nodata C:\QvwFolder\File.qvw
@dapostolopoylos
dapostolopoylos / MaxOfMaxValues.qvs
Created August 24, 2016 10:02
A QlikView Script that finds the maximum value in a field defined by the maximum value of another field for the same person... Ask if you don't understand... :)
SET ThousandSep=',';
SET DecimalSep='.';
SET MoneyThousandSep=',';
SET MoneyDecimalSep='.';
SET MoneyFormat='$#,##0.00;($#,##0.00)';
SET TimeFormat='h:mm:ss TT';
SET DateFormat='YYYY-MM-DD';
SET TimestampFormat='YYYY-MM-DD h:mm:ss[.fff] TT';
SET MonthNames='Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec';
SET DayNames='Mon;Tue;Wed;Thu;Fri;Sat;Sun';