[Draft} An Attempt To Use Linear Regression Algorithms To Predict Future Price Changes Of An Item Over Time

Predict the price of an Armadyl Chainskirt.

Below is some python code that reads and displays element data from an html webpage. In this example we pull the price of the item “Armadyl Chainskirt” by copy and pasting its Official Grand Exchange Page.

from requests_html import HTMLSession
session = HTMLSession()
url_for_item = 'http://services.runescape.com/m=itemdb_oldschool/Armadyl_chainskirt/viewitem?obj=11830'
r = session.get(url_for_item)
#line 4 needs to be changed to desired item that is being analyzed
print("These are anchor links connected to Twisted Bow GE Page:",r.html.links)
#price = r.html.find('#<span title=""', first=True)
#print(price)
about = r.html.find('.grandexchange .stats h3 span ', first=True)
final_value = (str(about)).strip("<Element 'span' title=''>")
final_value = final_value.replace(',','')
print(final_value)
# now we will take our value and append it to a .csv database
import csv
from time import gmtime, strftime
datestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime())
fields = [final_value]
with open(r'daily_price_of_arma_skirt.csv', 'a') as f:
    writer = csv.writer(f, delimiter=',')
    writer.writerow([final_value]+[datestamp])


#so far, we get the price of our item and edit a local csv file with the price and date.
#now we will make it so it opens automatically once per day with #Windows Task Scheduler

Automatic Positional Clicker With Time Intervals

import win32api, win32con, time
def click(x,y):
    win32api.SetCursorPos((x,y))
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
def script():
    while True:
        click(1793,889) #invent
        time.sleep(.2)
        click(1393,872)  #1
        time.sleep(.1)
        click(1393,872)  #1
        time.sleep(.1)
        click(1393,872)  #1
        time.sleep(4)
        click(1395,745) #2
        time.sleep(.1)
        click(1395,745) #2
        time.sleep(6)
        click(1501,782) #3
        time.sleep(.1)
        click(1501,782) #3
        time.sleep(7.5)
        click(1483,885) #4
        time.sleep(.1)
        click(1483,885) #4
        time.sleep(5)
        click(1456,845) #5
        time.sleep(7)
        click(1355,859) #6
        time.sleep(2.8)
        click(1273,822) #7
        time.sleep(7)
        click(1451,766) #8
        time.sleep(.1)
        click(1451,766) #8
        time.sleep(5.5)
        click(1498,870) #9
        time.sleep(.1)
        click(1498,870) #9
        time.sleep(4.2)
        click(1792,854)  #10.0
        time.sleep(5.5)
        click(1767,832) #11.0
        time.sleep(5)
        click(1279,999) #11.0
        time.sleep(5)     
#x, y = win32api.GetCursorPos()
#print(x,y)
script()

Data Scrubbing

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn import ensemble
from sklearn.metrics import mean_absolute_error
df = pd.read_csv("f:/brain/memory/Melbourne_housing_FULL.csv")
del df['Address']
del df['Method']
del df['SellerG']
del df['Date']
del df['Postcode']
del df['Lattitude']
del df['Longtitude']
del df['Regionname']
del df['Propertycount']
df.columns
features_df = pd.get_dummies(df, columns = ['Suburb','CouncilArea','Type'])
del features_df['Price']
x = features_df.values
y = df['Price'].values
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.3, shuffle = True)
model = ensemble.GradientBoostingRegressor(
    n_estimators = 150,
    learning_rate = 0.1,
    max_depth = 30,
    min_samples_split = 4,
    min_samples_leaf = 6,
    max_features = 0.6,
    loss = 'huber'
)
model.fit(x_train, y_train)
mse = mean_absolute_error(y_train, model.predict(x_train))
print("Training Set Mean Absolute Error: %.2f" % mse)
mse = mean_absolute_erro(y_test, model.predict(x_test))
print("Test Set Mean Absolute Error: %.2f" % mse)

Song_Writer Progress #3 "666"

second = 60
minute = 60*second
modes = "Ionian,Dorian,Phrygian,Lydian,Mixolydian,Aeolian,Locrian"
def main():
    def song_details():
            beat_division = input("what is the x/x beat division:") # a quarter note gets the beat, so four quarter notes a bar
            tempo = int(input("tempo is, in Beats Per Minute:"))
            song_length_sec = int(input("Song Length(in seconds):")) #song length, 165sec is nice
            song_length_min = song_length_sec/60
            print("-----------------------------------------------")
            print("The Beat Division is: "+str(beat_division)+".")
            print("The Tempo is: "+str(tempo)+" Beats Per Minute.")
            print("The Song Length is: "+str(song_length_sec)+" seconds.") 
            
            amount_of_beats = int(tempo*(song_length_min))
            print(amount_of_beats)
            
            
            
    song_details()
    
    
        

main()

Song_Writer Progress #2

#how long the song will be
second = 60
minute = 60*second
class Oedema5_Songs:
    def __init__(self, beat_division, temp, song_length):
            self.beat_division = input("what is the x/x beat division:") # a quarter note gets the beat, so four quarter notes a bar
            self.tempo = input("tempo is, in Beats Per Minute:")
            self.song_length = input("Song Length(in seconds):") #song length
    def song_details(self):  #gets information about the drums
            return '{} {} {}'.format(self.beat_division, self.tempo, self.song_length)
songx1 = Oedema5_Songs(4/4,150,165)

More Object-Orientated Programming

class Employee: 
    
    def __init__(self,first, last, pay):
        self.first = first
        self.last = last
        self.email = first+'.'+last+"@company.com"
        self.pay = pay
        
    def fullname(self):
        return '{} {}'.format(self.first, self.last)
        
emp_1 = Employee("Corey","Schafer",50000)
emp_2 = Employee("test","user",60000)

#print(emp_1)
#print(emp_2)
print(emp_1.email)
print(emp_2.email)
print(emp_1.fullname())

Object-Oriented Programming

import numpy as np
class Coordinate(object):  #class tells python you are making an object. #class name/type(parent object)
    def __init__(self, x, y):  #defines attributes that let us interact with the object
        self.x = x  #these attributes only work with its class
        self.y = y

    def distance(self, dist):  #defines attributes that let us interact with the object
        dist = numpy.linalg.norm(x-y)
        x_diff_sq = (self.x-other.x)**2 #these attributes only work with its class
        y_diff_sq = (self.y-other.y)**2
        return(x_diff_sq + y_diff_sq)**0.5
#self is a parameter that references the instance of this class |  
#methods like __init__ are like a function that only work with this class
c = Coordinate(3,4)
zero = Coordinate (0,0)
print(c.distance(zero))