I get this error
r studio debug location is approximate because source is not available
although I'm on the newest version of R studio with no backward slashes available in my function
My function:
calculate_depreciation_percentage_v1 = function (end_of_life_value_perc_temp, immediate_loss_of_value_percent, theoretische_afschrijfperiode, restwaarde_bouw_perc,bouwwaarde_perc,perceelwaarde_perc,current_nr_of_years,groeivoet_waarde_perceel, cash_flow_year_1, maintanance_cost_weights) {
# browser()
# in-function parameters: moved all of them to main script
# declare variables
end_of_life_value_perc_local = repmat(-1234, size(immediate_loss_of_value_percent,1), size(immediate_loss_of_value_percent,2))
#CALCULATIONS
for (RV_loop_local in 1:size(immediate_loss_of_value_percent,1)) { #for the first calculation, calculate...
jaarlijks_afschrijfpercentage_bouwwaarde = (1-immediate_loss_of_value_percent[RV_loop_local,1] - restwaarde_bouw_perc) / theoretische_afschrijfperiode #ok
depecriation_vec_bouwwaarde = seq(from = 0, to=(jaarlijks_afschrijfpercentage_bouwwaarde*size(immediate_loss_of_value_percent,2))-jaarlijks_afschrijfpercentage_bouwwaarde , by=jaarlijks_afschrijfpercentage_bouwwaarde ) + immediate_loss_of_value_percent[RV_loop_local,1]
# depecriation_vec_bouwwaarde[1] = immediate_loss_of_value_percent[RV_loop,1] mss toepassen op hele vector, kan wel
remaining_value_vec_bouwwaarde = (-cash_flow_year_1)*(1-depecriation_vec_bouwwaarde) # it assumed you cannot go under 0, but the program does not detect if you do...
# tis niet juist
#
# (-cash_flow_year_1*bouwwaarde_perc)*
# the remaining value
weight_vector_perceelwaarde_FV = repmat(-1234, 1, size(immediate_loss_of_value_percent,2))
for (current_nr_of_years_local in 1:size(immediate_loss_of_value_percent,2)) {
# (-perceelwaarde_perc *cash_flow_year_1)
weight_vector_perceelwaarde_FV[current_nr_of_years_local] = (-perceelwaarde_perc *cash_flow_year_1)*((1+groeivoet_waarde_perceel)^current_nr_of_years_local)
# weight_vector_perceelwaarde_FV[current_nr_of_years_local] = (-perceelwaarde_perc *cash_flow_year_1)*((1+groeivoet_waarde_perceel)^current_nr_of_years_local)
# weight_vector_perceelwaarde_FV
# ,current_nr_of_years,groeivoet_waarde_perceel #
# -bouwwaarde_perc*cash_flow_year_1
# end_of_life_value_perc_local = [RV_loop, current_nr_of_years] =
}
# depecriation_vec_bouwwaarde*bouwwaarde_perc
# weight_vector_perceelwaarde_FV*perceelwaarde_perc
weighted_average_residual_value_vec = weight_vector_perceelwaarde_FV + (bouwwaarde_perc*remaining_value_vec_bouwwaarde)
weight_vector_perceelwaarde_FV
(bouwwaarde_perc*remaining_value_vec_bouwwaarde)
browser()
}
# weighted_average_depreciation_matrix[RV_loop_local,:] = weighted_average_depreciation_vector
# weighted_average_depreciation_matrix <- cbind(x, y, z)
#simulation_bouwwaarde = end_of_life_value_perc_temp[1]-jaarlijks_afschrijfpercentage_bouwwaarde*20
# finVal = 1 * (0.0125 + 1)^20
# return(...)
}
Version
RStudio 2021.09.2+382 "Ghost Orchid" Release (fc9e217980ee9320126e33cdf334d4f4e105dc4f, 2022-01-04) for Windows
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.8 Chrome/69.0.3497.128 Safari/537.36
Related
I was trying to deploy my NLP model to Heroku, and I got the following error in the logs upon trying to predict the result of the inputs-
2022-09-07T15:36:35.497488+00:00 app[web.1]: if self.n_features_ != n_features:
2022-09-07T15:36:35.497488+00:00 app[web.1]: AttributeError: 'DecisionTreeClassifier' object has no attribute 'n_features_'
2022-09-07T15:36:35.498198+00:00 app[web.1]: 10.1.22.85 - - [07/Sep/2022:15:36:35 +0000] "POST /predict HTTP/1.1" 500 290 "https://stocksentimentanalysisapp.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"
This specific line is strange considering I never used a Decision Tree Classifier, only Random Forest-
AttributeError: 'DecisionTreeClassifier' object has no attribute 'n_features_'
The model runs perfectly well in Jupyter Notebook. This issue began only when I tried to deploy it.
Here is my model-
import pandas as pd
import pickle
df = pd.read_csv('D:\Sa\Projects\Stock Sentiment Analysis\data\data.csv', encoding='ISO-8859-1')
train = df[df['Date']<'20150101']
test = df[df['Date']>'20141231']
#Removing non-alphabetic characters
data = train.iloc[:,2:27]
data.replace('[^a-zA-Z]', ' ', regex=True, inplace=True)
#Renaming columns to numerical index
idx_list = [i for i in range(25)]
new_index = [str(i) for i in idx_list]
data.columns = new_index
for index in new_index:
data[index] = data[index].str.lower()
combined_headlines = []
for row in range(0, len(data.index)):
combined_headlines.append(' '.join(str(x) for x in data.iloc[row, 0:25]))
from sklearn.ensemble import RandomForestClassifier
#Bag of words
from sklearn.feature_extraction.text import CountVectorizer
count_vectorizer = CountVectorizer(ngram_range=(2,2))
train_data = count_vectorizer.fit_transform(combined_headlines)
pickle.dump(count_vectorizer, open('countVectorizer.pkl', 'wb'))
rfc = RandomForestClassifier(n_estimators=200, criterion='entropy')
rfc.fit(train_data, train['Label'])
test_transform = []
for row in range(0, len(data.index)):
test_transform.append(' '.join(str(x) for x in data.iloc[row, 2:27]))
test_data = count_vectorizer.transform(test_transform)
predictions = rfc.predict(test_data)
# Saving model to disk
pickle.dump(rfc, open('randomForestClassifier.pkl', 'wb'))
Please help me understand what is going wrong.
I am using this page:
https://www.google.com/search?q=ford+fusion+msrp&oq=ford+fusion+msrp&aqs=chrome.0.0l6.2942j0j7&sourceid=chrome&ie=UTF-8
I am trying to get the this element: class="_XWk"
page = HTTParty.get('https://www.google.com/search?q=ford+fusion+msrp&oq=ford+fusion+msrp&aqs=chrome.0.0l6.11452j0j7&sourceid=chrome&ie=UTF-8')
parse_page = Nokogiri::HTML(page)
parse_page.css('_XWk')
Here I can see the whole page in parse_page but when I try the .cc('classname') I don't see anything. Am I using the method the wrong way?
Check out the SelectorGadget Chrome extension to grab css selectors by clicking on the desired element in the browser.
It's because of a simple typo, e.g. . (dot) before selector as ran already mentioned.
In addition, the next problem might occur because no HTTP user-agent is specified thus Google will block a request eventually and you'll receive a completely different HTML that will contain an error message or something similar without the actual data you was looking for. What is my user-agent.
Pass a user-agent:
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19582"
}
HTTParty.get("https://www.google.com/search", headers: headers)
Iterate over container to extract titles from Google Search:
data = doc.css(".tF2Cxc").map do |result|
title = result.at_css(".DKV0Md")&.text
Code and example in the online IDE:
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19582"
}
params = {
q: "ford fusion msrp",
num: "20"
}
response = HTTParty.get("https://www.google.com/search",
query: params,
headers: headers)
doc = Nokogiri::HTML(response.body)
data = doc.css(".tF2Cxc").map do |result|
title = result.at_css(".DKV0Md")&.text
link = result.at_css(".yuRUbf a")&.attr("href")
displayed_link = result.at_css(".tjvcx")&.text
snippet = result.at_css(".VwiC3b")&.text
puts "#{title}#{snippet}#{link}#{displayed_link}\n\n"
-------
'''
2020 Ford Fusion Prices, Reviews, & Pictures - Best Carshttps://cars.usnews.com/cars-trucks/ford/fusionhttps://cars.usnews.com › Cars › Used Cars › Used Ford
Ford® Fusion Retired | Now What?Not all vehicles qualify for A, Z or X Plan. All Mustang Shelby GT350® and Shelby® GT350R prices exclude gas guzzler tax. 2. EPA-estimated city/hwy mpg for the ...https://www.ford.com/cars/fusion/https://www.ford.com › cars › fusion
...
'''
Alternatively, you can achieve this by using Google Organic Results API from SerpApi. It's a paid API with a free plan.
The difference in your case is that you don't need to figure out what the correct selector is or why results are different in the output since it's already done for the end-user.
Basically, the only thing that needs to be done is just to iterate over structured JSON and get the data you were looking for.
Example code:
require 'google_search_results'
params = {
api_key: ENV["API_KEY"],
engine: "google",
q: "ford fusion msrp",
hl: "en",
num: "20"
}
search = GoogleSearch.new(params)
hash_results = search.get_hash
data = hash_results[:organic_results].map do |result|
title = result[:title]
link = result[:link]
displayed_link = result[:displayed_link]
snippet = result[:snippet]
puts "#{title}#{snippet}#{link}#{displayed_link}\n\n"
-------
'''
2020 Ford Fusion Prices, Reviews, & Pictures - Best Carshttps://cars.usnews.com/cars-trucks/ford/fusionhttps://cars.usnews.com › Cars › Used Cars › Used Ford
Ford® Fusion Retired | Now What?Not all vehicles qualify for A, Z or X Plan. All Mustang Shelby GT350® and Shelby® GT350R prices exclude gas guzzler tax. 2. EPA-estimated city/hwy mpg for the ...https://www.ford.com/cars/fusion/https://www.ford.com › cars › fusion
...
'''
P.S - I wrote a blog post about how to scrape Google Organic Search Results.
Disclaimer, I work for SerpApi.
It looks like something is swapping the classes so what you see in the browser is not what you are getting from the http call. In this case from _XWk to _tA
page = HTTParty.get('https://www.google.com/search?q=ford+fusion+msrp&oq=ford+fusion+msrp&aqs=chrome.0.0l6.11452j0j7&sourceid=chrome&ie=UTF-8')
parse_page = Nokogiri::HTML(page)
parse_page.css('._tA').map(&:text)
# >>["Up to 23 city / 34 highway", "From $22,610", "175 to 325 hp", "192″ L x 73″ W x 58″ H", "3,431 to 3,681 lbs"]
Change parse_page.css('_XWk') to parse_page.css('._XWk')
Note the dot (.) difference. The dot references a class.
Using parse_page.css('_XWk'), nokogiri doesn't know wether _XWk is a class, id, data attribute etc..
I am running Xming on my local machine which is a windows box. I am connecting to Xming from an AIX box. I am connecting as root, because I need to perform a software installation with X11 windows. I am able to pull up xterm for example, and a X11 window pops up with Xterm, but the keyboard is all jacked up. Everything seems to be off by one or worse, and lots of other keys just flat out dont work such as the enter key. The xterm application isnt important, but every X11 window I open has this problem.
For example: A single press and release of the key:
--- row 1 ---
q = q
w = q
e = w
r = e
...
[ = p
] = [
\ = \
Enter = ]
--- row 2 ---
a = nothing
s = a
d = s
...
: = l
' = ;
--- row 3 ---
z = z
x = nothing
c = z
v = x
b = c
n = v
m = b
< = n
> = m
/ = ,
--- misc ---
space = space
tab = tab
` = '
1-9 = 1-9 (these are the only ones that are correct)
anything on the numpad = some variation of ^[[F (numpad 1 for example)
ctrl = \
alt = nothing
backspace = nothing
del = ^[[3~
esc = `
Here is the output of my setxkbmap -print
bash.root#myServer:/ # setxkbmap -print
Couldn't interpret _XKB_RULES_NAMES property
Use defaults: rules - 'xorg' model - 'pc101' layout - 'us'
xkb_keymap {
xkb_keycodes { include "xfree86+aliases(qwerty)" };
xkb_types { include "complete" };
xkb_compat { include "complete" };
xkb_symbols { include "pc+us" };
xkb_geometry { include "pc(pc101)" };
};
The error message
Couldn't interpret _XKB_RULES_NAMES property
tells you what the problem is: setxkbmap cannot find the configuration your X server is expecting, so it falls back (to a value which does not work for you). Xming's website has a trouble-shooting page which may help.
I'm trying to differentiate AJAX requests from standard HTTP requests in a Oracle PL/SQL environment (Oracle 10g DB). I have added X-Requested-With to my PlsqlCGIEnvironmentList and indeed see a value when I print the CGI variables with owa_util.print_cgi_env;.
Here is an example:
PLSQL_GATEWAY = WebDb
GATEWAY_IVERSION = 3
SERVER_SOFTWARE = Oracle-Application-Server-10g/10.1.2.0.2 Oracle-HTTP-Server
GATEWAY_INTERFACE = CGI/1.1
SERVER_PORT = 7779
SERVER_NAME = myserver.com
REQUEST_METHOD = GET
QUERY_STRING = action=change_contact&doc_id=10032
PATH_INFO = /!fc
SCRIPT_NAME = /script
REMOTE_ADDR = 172.30.170.125
SERVER_PROTOCOL = HTTP/1.1
REQUEST_PROTOCOL = HTTP
REMOTE_USER = myuser
HTTP_USER_AGENT = Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0
HTTP_HOST = myserver.com
HTTP_ACCEPT = text/html, */*; q=0.01
HTTP_ACCEPT_LANGUAGE = en-US,en;q=0.5
HTTP_REFERER = http://myserver.com/script/!fc?action=doc&doc_id=10032
HTTP_ORACLE_ECID = 175007308883,1
HTTP_ORACLE_CACHE_VERSION = 10.1.2
WEB_AUTHENT_PREFIX =
DAD_NAME = script
DOC_ACCESS_PATH = docs
DOCUMENT_TABLE = wpg_document
PATH_ALIAS =
REQUEST_CHARSET = WE8MSWIN1252
REQUEST_IANA_CHARSET = WINDOWS-1252
SCRIPT_PREFIX =
X-Requested-With = XMLHttpRequest
HTTP_COOKIE = SMIDENTITY=0emF6I4...
The problem is, owa_util.get_cgi_env('X-Requested-With') is always null even for requests like the one above that shows X-Requested-With = XMLHttpRequest
Any idea what my problem might be?
I don't have access to 10g, but I looked at the OWA_UTIL code in 11gR2.
The item of interest is the UPPER function being applied in get_cgi_env.
It is possible that in 10g, it is doing the UPPER on one end of the comparison but not the other, so any variable including lowercase isn't matching.
procedure print_cgi_env is
begin
for i in 1..owa.num_cgi_vars
loop
htp.print(owa.cgi_var_name(i)||' = '||owa.cgi_var_val(i)||htf.nl);
end loop;
end;
function get_cgi_env(param_name in varchar2) return varchar2 is
upper_param_name varchar2(2000) := upper(param_name);
begin
for i in 1..owa.num_cgi_vars
loop
if (upper(owa.cgi_var_name(i)) = upper_param_name)
then return(owa.cgi_var_val(i));
end if;
end loop;
return NULL;
end;
Check your OWA_UTIL.
I'm just trying to get my head around a multidimensional array creation from a perl script i'm currently converting to Ruby, I have 0 experience in Perl, as in i opened my first Perl script this morning.
Here is the original loop:
my $tl = {};
for my $zoom ($zoommin..$zoommax) {
my $txmin = lon2tilex($lonmin, $zoom);
my $txmax = lon2tilex($lonmax, $zoom);
# Note that y=0 is near lat=+85.0511 and y=max is near
# lat=-85.0511, so lat2tiley is monotonically decreasing.
my $tymin = lat2tiley($latmax, $zoom);
my $tymax = lat2tiley($latmin, $zoom);
my $ntx = $txmax - $txmin + 1;
my $nty = $tymax - $tymin + 1;
printf "Schedule %d (%d x %d) tiles for zoom level %d for download ...\n",
$ntx*$nty, $ntx, $nty, $zoom
unless $opt{quiet};
$tl->{$zoom} = [];
for my $tx ($txmin..$txmax) {
for my $ty ($tymin..$tymax) {
push #{$tl->{$zoom}},
{ xyz => [ $tx, $ty, $zoom ] };
}
}
}
and what i have so far in Ruby:
tl = []
for zoom in zoommin..zoommax
txmin = cm.tiles.xtile(lonmin,zoom)
txmax = cm.tiles.xtile(lonmax,zoom)
tymin = cm.tiles.ytile(latmax,zoom)
tymax = cm.tiles.ytile(latmin,zoom)
ntx = txmax - txmin + 1
nty = tymax - tymin + 1
tl[zoom] = []
for tx in txmin..txmax
for ty in tymin..tymax
tl[zoom] << xyz = [tx,ty,zoom]
puts tl
end
end
end
The part i'm unsure of is nested right at the root of the loops, push #{$tl->{$zoom}},{ xyz => [ $tx, $ty, $zoom ] };
I'm sure this will be very simple for a seasoned Perl programmer, thanks! `
The Perl code is building up a complex data structure in $tl -- hash, array, hash, array:
$tl{$zoom}[i]{xyz}[j] = $tx # j = 0
$tl{$zoom}[i]{xyz}[j] = $ty # j = 1
$tl{$zoom}[i]{xyz}[j] = $zoom # j = 2
So I think the key line in your Ruby code should be like this:
tl[zoom] << { 'xzy' => [tx,ty,zoom] }
Note also that the root item ($tl) refers to a hash in the Perl code, while your Ruby code initializes it to be an array. That difference might cause problems for you, depending on the values that $zoom takes.