fb prophet regressor underestimated - prediction

I am working on monthly sales data. especially in the month of June, the sales are almost 3*X. how do I add a regressor? I tried to create a binary regressor but the value is still underestimated. how can I increase the impact of the regressor?
def main_season(ds):
date = pd.to_datetime(ds)
if date.month > 3 and date.month < 7:
return 1
else:
return 0
X_tr['main_season'] = X_tr['ds'].apply(main_season)
def peak_season(ds):
date = pd.to_datetime(ds)
if date.month == 6:
return 1
else:
return 0
X_tr['peak_season'] = X_tr['ds'].apply(peak_season)

Related

How to calculate period between a specific date?

I'm studying Flutter and in my application I need to calculate how many days are left until the 17th of the next month. There is no way to have a specific date, so it would be crucial to have today's date and add 1 month and calculate how many days are left.
For example: Today is 2021-09-09 and there are 38 days to 2021-10-17. The function does not calculate the 17th of the current month, but the following month.
Any idea how to make a function that takes the current date, adds 1 month and calculates how many days are left until the 17th? Thanks.
Basically copy the DateTime object with 1 added to the current month number and the day set to the 17th. Then subtract the two DateTime objects and convert the resulting Duration to days. It's important to perform all calculations in UTC so that Daylight Saving Time adjustments aren't a factor.
/// Returns the number of days to the specified [day] in the month following
/// [startDate].
int daysToNextMonthDay(DateTime startDate, int day) {
// Recreate `startDate` as a UTC `DateTime`. We don't care about the
// time.
//
// Note that this isn't the same as `startDate.toUtc()`. We want a UTC
// `DateTime` with specific values, not necessarily the UTC time
// corresponding to same moment as `startDate`.
startDate = DateTime.utc(startDate.year, startDate.month, startDate.day);
var nextMonthDay = DateTime.utc(startDate.year, startDate.month + 1, day);
// Verify that the requested day exists in the month.
if (nextMonthDay.day != day) {
throw ArgumentError(
'Day $day does not exist for the month following ${startDate.month}',
);
}
return nextMonthDay.difference(startDate).inDays;
}
void main() {
var now = DateTime(2021, 9, 9);
print(daysToNextMonthDay(now, 17)); // Prints: 38
}
try this:
void main() {
DateTime date = DateTime.now();
print(daysLeft(date.subtract(Duration(days: 1))));
}
bool isLeapYear(int year) {
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
int daysLeft(DateTime date){
int daysLeft = 0;
switch(date.month){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: daysLeft = 31 - date.day + 17; break;
case 4:
case 6:
case 9:
case 11: daysLeft = 30 - date.day + 17; break;
case 2: if(isLeapYear(date.year)){
daysLeft = 29 - date.day + 17;
break;
}else{
daysLeft = 28 - date.day + 17;
}
}
return daysLeft;
}

Record selection based on Next Sunday through end of 2 months out

I want to pull all records from the {#Calc Promise Date} field that have a date range of next Sunday through the end of next month. I have the end of next month part, and tried the next Sunday part using some similar examples on this site, but I am still off target on the next Sunday part.
Original try that would have a start of 5 days after today:
{#Calc Promise Date}>=DateSerial(Year(currentdate),Month(currentdate),Day(currentdate)+5)
and {#Calc Promise Date}<DateSerial(Year(currentdate),Month(currentdate)+2,1)
This was modified from help given to another user, but does not cover how to adjust the start date of the range to next Sunday.
I tried the following and have errors as I do not understand the correct layout, or if this will help in getting my desired start date.
{#Calc Promise Date} >= if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 1
then DateSerial(Year(currentdate),Month(currentdate),1+7)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 2
then DateSerial(Year(currentdate),Month(currentdate),1+6)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 3
then DateSerial(Year(currentdate),Month(currentdate),1+5)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 4
then DateSerial(Year(currentdate),Month(currentdate),1+4)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 5
then DateSerial(Year(currentdate),Month(currentdate),1+3)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 6
then DateSerial(Year(currentdate),Month(currentdate),1+2)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 7
then DateSerial(Year(currentdate),Month(currentdate),1+1)
and {#Calc Promise Date}<DateSerial(Year(currentdate),Month(currentdate)+2,1)
You are almost done as per my knowledge writing this formula in Record Selection doesn't work instead create saperate formulas and write on liner in record selection.
Create a formula Start Date:
if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 1
then DateSerial(Year(currentdate),Month(currentdate),1+7)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 2
then DateSerial(Year(currentdate),Month(currentdate),1+6)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 3
then DateSerial(Year(currentdate),Month(currentdate),1+5)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 4
then DateSerial(Year(currentdate),Month(currentdate),1+4)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 5
then DateSerial(Year(currentdate),Month(currentdate),1+3)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 6
then DateSerial(Year(currentdate),Month(currentdate),1+2)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),1),1) = 7
then DateSerial(Year(currentdate),Month(currentdate),1+1)
and {#Calc Promise Date}<DateSerial(Year(currentdate),Month(currentdate)+2,1)
Create a Formula End Date:
DateSerial(Year(currentdate),Month(currentdate)+2,1)
Now your Record Selection:
{#Calc Promise Date}>={#Start Date}
and {#Calc Promise Date}<{#End Date}

Tableau: last value calculation in calculated field

my dataset is like this
KPI VALUE TYPE DATE
coffee break duration 11 0 30/06/2015
coffee break duration 12 0 31/07/2015
coffee break duration 10 0 30/11/2014
coffee break duration 10 0 31/12/2014
coffee expense 20 1 31/07/2015
coffee expense 20 1 31/12/2014
coffee consumers 15 -1 31/07/2015
coffee consumers 17 -1 31/12/2014
for Type, 0 means minutes, 1 means dollars and -1 means people
I want to get a table like this
KPI Year(date) YTD
coffee break duration 2015 11,5
coffee break duration 2014 10
....
YTD calculation is:
if sum([TYPE]) = 0 then avg([VALUE])
elseif sum([TYPE]) > 0 then sum([VALUE])
elseif sum([TYPE]) < 0 then [last value for the considered year]
end
By [Last value for the considered year] I mean the last entry available, in a year if my table is set to Year, otherwise it has to change dynamically based on what Timespan I want to show.
What can I do to have [last value for the considered year] as a calc field ready to use in my YTD calc?
Many thanks,
Stefania
If I understand your question, than you can use LOD in the IF statement
if sum(type) = 0 then avg([value])
elseif sum([type]) > 0 then sum(value)
elseif sum([type]) < 0 then max(if [date] = { INCLUDE kpi: max(date)} then [value] end)
end
If there are several values on the last day of the considered year, it would take the biggest value
I slightly modified your data to show that results are working correctly

Passing an object of a class to a method in the class

I wrote a simple date class for practice but I can't seem to pass the objects in the class to the methods within the class. The class is supposed to be able to accept test dates, correct them if they are out of range and then print the correct date. Here is the code
class Date:
month = int
day = int
year = int
def setDate(self, month, day, year)
HIGH_MONTH = 12
HIGHEST_DAYS = ['none',31,29,31,30,31,30,31,31,30,31,30,31]
if month > HIGH_MONTH:
month = HIGH_MONTH
elif month < 1:
month = 1
else:
month = month
if day > HIGHEST_DAYS[month]:
day = HIGHEST_DAYS[month]
elif day < 1:
day = 1
else:
day = day
def showDate(self):
print 'Date:',month,'/',day,'/',year
#These are my tests
birthday=Date()
graduation=Date()
birthday.month=6
birthday.day=24
birthday.year=1984
graduation.setDate(5,36,2016)
birthday.showDate()
graduation.showDate()
What I get is a NameError: global name 'month' is not defined
In order for you to use a "global" variable in your class, assign the variables to self.variable_name as such:
class Date:
month = int
day = int
year = int
def setDate(self, month, day, year):
HIGH_MONTH = 12
HIGHEST_DAYS = [None,31,29,31,30,31,30,31,31,30,31,30,31]
if month > HIGH_MONTH:
month = HIGH_MONTH
elif month < 1:
month = 1
else:
month = month
if day > HIGHEST_DAYS[month]:
day = HIGHEST_DAYS[month]
elif day < 1:
day = 1
else:
day = day
self.year = year
self.month = month
self.day = day
def showDate(self):
print 'Date:',self.month,'/',self.day,'/',self.year
>>> birthday=Date()
>>> graduation=Date()
>>> birthday.month=6
>>> birthday.day=24
>>> birthday.year=1984
>>> graduation.setDate(5,36,2016)
>>> birthday.showDate()
Date: 6 / 24 / 1984
>>> graduation.showDate()
Date: 5 / 31 / 2016
>>>

how to get the range date in vb6

i have 2 date picker
Dim pday, eitday, otherday, tpenalty, difday, subpenalty As Integer
difday = Val(L1.Caption) - Val(L2.Caption)
pday = 7
eitday = 8
otherday = difday - eitday
tpenalty = 25
If difday <= pday Then
PENALTY.Caption = 0
ElseIf difday = eitday Then
PENALTY.Caption = tpenalty
ElseIf difday > eitday Then
For i = 0 To otherday - 1
subpenalty = subpenalty + 5
Next i
PENALTY.Caption = tpenalty + subpenalty
End If
the problem is when the month is change the calculation is invalid.
I'm guessing based on your code (as many things are unclear), but this should give the number of days between two dates:
difday = DateDiff("d", StartDate, EndDate)
I've used StartDate and EndDate to signify the start and end of the lone period which are used to set L1 and L2, as you shouldn't be converting from strings to dates for calculations.