syntax error in LogisticRegression - logistic-regression

I get a syntax error in the following command of LogisticRegression. Can someone please advise where I might be going wrong here?
from sklearn import linear_model
lm = linear_model.LogisticRegression (C = 1e3)
lm.fit (m[:lags].T, np.sign(m[lags])
LogisticRegression (penalty ='l2', tol = .0001, C = 1000000.0, class_weight = None, dual = False, fit_intercept = True,
intercept_scaling = 1, random_state = None, solver ='liblinear', max_iter = 100, multi_class ='ovr',verbose = 0,
warm_start = False, n_jobs = 1)
Error:
File "<ipython-input-33-529ff9190586>", line 4
LogisticRegression (penalty ='l2', tol = .0001, C = 1000000.0, class_weight = None, dual = False, fit_intercept = True,
^
SyntaxError: invalid syntax

you have missing closing parenthesis here:
lm.fit (m[:lags].T, np.sign(m[lags]) <--
change to
lm.fit (m[:lags].T, np.sign(m[lags]))

Related

Why am I getting a write after write hazard in vulkan validation layers?

I am trying to get proper synchronization working in trying to get a compute shader writing to an image. However, when I enable validation layers I get the following errors:
[ SYNC-HAZARD-WRITE-AFTER-WRITE ] Object 0: handle = 0x4b7df1000000002f, type = VK_OBJECT_TYPE_IMAGE_VIEW; | MessageID = 0x5c0ec5d6 | vkCmdDispatch: Hazard WRITE_AFTER_WRITE for VkImageView 0x4b7df1000000002f[], in VkCommandBuffer 0x558d7b2aec00[], and VkPipeline 0x95a125000000001a[], VkDescriptorSet 0x944a2c0000000039[], type: VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, imageLayout: VK_IMAGE_LAYOUT_GENERAL, binding #0, index 0. Access info (usage: SYNC_COMPUTE_SHADER_SHADER_STORAGE_WRITE, prior_usage: SYNC_IMAGE_LAYOUT_TRANSITION, write_barriers: 0, command: vkCmdPipelineBarrier, seq_no: 1, reset_no: 1).
[ SYNC-HAZARD-WRITE-AFTER-WRITE ] Object 0: handle = 0xb12fb2000000002c, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x5c0ec5d6 | vkCmdPipelineBarrier: Hazard WRITE_AFTER_WRITE for image barrier 0 VkImage 0xb12fb2000000002c[]. Access info (usage: SYNC_IMAGE_LAYOUT_TRANSITION, prior_usage: SYNC_COMPUTE_SHADER_SHADER_STORAGE_WRITE, write_barriers: 0, command: vkCmdDispatch, seq_no: 2, reset_no: 1).
The relevant code is as follows:
vkBeginCommandBuffer(cmdBuffer, &cmdBufBeginInfo);
VkImageMemoryBarrier toGeneralBarrier = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.pNext = NULL,
.srcAccessMask = 0,
.dstAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED,
.newLayout = VK_IMAGE_LAYOUT_GENERAL,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = vr.swapImages[imageIndex],
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = 1,
},
};
vkCmdPipelineBarrier(
cmdBuffer,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
0,
0,
NULL,
0,
NULL,
1,
&toGeneralBarrier);
// vkCmdBindPipeline, vkCmdBindDescriptorSets is left out, not interesting
vkCmdDispatch(cmdBuffer, dispatchX, dispatchY, 1); // hazard here
VkImageMemoryBarrier toPresentBarrier = {
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
.pNext = NULL,
.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT,
.dstAccessMask = 0,
.oldLayout = VK_IMAGE_LAYOUT_GENERAL,
.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
.image = vr.swapImages[imageIndex],
.subresourceRange = {
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
.baseMipLevel = 0,
.levelCount = 1,
.baseArrayLayer = 0,
.layerCount = 1,
},
};
vkCmdPipelineBarrier( // hazard here?
cmdBuffer,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
0,
0,
NULL,
0,
NULL,
1,
&toPresentBarrier);
// vkEndCommandBuffer, vkQueueSubmit, vkQueuePresentKHR, ... left out
I have tried searching for a mistake in my code that code have caused these errors but I could not find one. Is there something wrong with my pipeline barriers and how do I fix this?

how to read json file array objets with python flask

I have a problem with read a file JSON, that file contains an array objects like this:
[{"some": 1, "list": [{"one":1}]},{"some": 1, "list": [{"one":1}]}]
my code is like below:
ls_plano = json.loads(open("tests/mocks/lsplano_itens_pessoais.json", encoding="utf8").read())
show me this error:
I try to read that file and put that file in ls_plano to read and assign to the other values like this:
ls_plano = json.loads(open("tests/mocks/lsplano_itens_pessoais.json", encoding="utf8").read())
if ls_plano is not None:
for plano in ls_plano:
temp_plano = {}
temp_plano["inPlanoPersonalizado"] = plano.get("inPlanoPersonalizado")
temp_plano["inSelecionado"] = plano.get("inSelecionado")
if plano.get("lsChassi"):
temp_plano["lsChassi"] = self.__map_ls_chassi(plano.get("lsChassi", []))
if plano.get("lsTipoObjetoSegurado"):
temp_plano["lsTipoObjetoSegurado"] = self.__map_ls_tipo_ob_segurado(
plano.get("lsTipoObjetoSegurado")
)
if plano.get("lsComissao"):
temp_plano["lsComissao"] = self.__map_ls_comissao(plano.get("lsComissao", []))
if plano.get("lsParcela"):
temp_plano["lsParcela"] = self.__map_ls_items(plano.get("lsParcela", []))
temp_plano["nmIdentificadorPlano"] = plano.get("nmIdentificadorPlano")
temp_plano["nmPlano"] = plano.get("nmPlano")
temp_plano["nrPlano"] = plano.get("nrPlano")
temp_plano["vlAdicionalFracionamento"] = plano.get("vlAdicionalFracionamento")
temp_plano["vlAssistenciaFacultativa"] = plano.get("vlAssistenciaFacultativa")
temp_plano["vlCobranca"] = plano.get("vlCobranca")
temp_plano["vlComercial"] = plano.get("vlComercial")
temp_plano["vlIof"] = plano.get("vlIof")
temp_plano["vlPremioLiquido"] = plano.get("vlPremioLiquido")
temp_plano["vlPremioNet"] = plano.get("vlPremioNet")
temp_plano["vlPremioTarifa"] = plano.get("vlPremioTarifa")
temp_plano["vlPremioTotal"] = plano.get("vlPremioTotal")
temp_plano["vlTotalComissao"] = plano.get("vlTotalComissao")
temp_plano["vlTotalDesconto"] = plano.get("vlTotalDesconto")
resp.append(temp_plano)
return resp
please help me, thanks for your attention.
Try to use with when opening files, it's a better approach, see here more info.
This code is working:
import sys
# Reading the json file
try:
with open("myjsonfile_list_of_dicts.json", "r") as read_content:
ls_plano: dict = json.load(read_content)
except (FileNotFoundError, PermissionError, OSError, ValueError) as e:
print(f"Error opening the file: {e}")
sys.exit()
# Parsing
try:
resp = []
if ls_plano is not None:
for plano in ls_plano:
temp_plano = {"inPlanoPersonalizado": plano.get("inPlanoPersonalizado"),
"inSelecionado": plano.get("inSelecionado")}
if plano.get("lsChassi"):
temp_plano["lsChassi"] = self.__map_ls_chassi(plano.get("lsChassi", []))
if plano.get("lsTipoObjetoSegurado"):
temp_plano["lsTipoObjetoSegurado"] = self.__map_ls_tipo_ob_segurado(
plano.get("lsTipoObjetoSegurado")
)
if plano.get("lsComissao"):
temp_plano["lsComissao"] = self.__map_ls_comissao(plano.get("lsComissao", []))
if plano.get("lsParcela"):
temp_plano["lsParcela"] = self.__map_ls_items(plano.get("lsParcela", []))
temp_plano["nmIdentificadorPlano"] = plano.get("nmIdentificadorPlano")
temp_plano["nmPlano"] = plano.get("nmPlano")
temp_plano["nrPlano"] = plano.get("nrPlano")
temp_plano["vlAdicionalFracionamento"] = plano.get("vlAdicionalFracionamento")
temp_plano["vlAssistenciaFacultativa"] = plano.get("vlAssistenciaFacultativa")
temp_plano["vlCobranca"] = plano.get("vlCobranca")
temp_plano["vlComercial"] = plano.get("vlComercial")
temp_plano["vlIof"] = plano.get("vlIof")
temp_plano["vlPremioLiquido"] = plano.get("vlPremioLiquido")
temp_plano["vlPremioNet"] = plano.get("vlPremioNet")
temp_plano["vlPremioTarifa"] = plano.get("vlPremioTarifa")
temp_plano["vlPremioTotal"] = plano.get("vlPremioTotal")
temp_plano["vlTotalComissao"] = plano.get("vlTotalComissao")
temp_plano["vlTotalDesconto"] = plano.get("vlTotalDesconto")
resp.append(temp_plano)
return resp
except (KeyError, TypeError) as e:
print(f"Error parsing the json file: {e}")
Recommendations:
Comment the code
Use try-except
Open files with 'with'

getting 'Assertion failed' while running the code 'gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)'

import numpy as np
import cv2
face_cascade = cv2.CascadeClassifier('E:/DATA
ANALYTICS/IMARTICUS/PGA06/haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('E:/DATA ANALYTICS/IMARTICUS/PGA06/haarcascade_eye.xml')
img = cv2.imread("E:\\DATA ANALYTICS\\IMARTIC`US\\PGA06\\images\\chiru(1).jpeg")
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
eyes = eye_cascade.detectMultiScale(roi_gray)
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
cv2.imshow('img',img)
cv2.waitKey(0)
cv2.destroyAllWindows()
getting the following error while running the code
error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'
How i get resolve the issue

construct an small app using shiny, after i code a loop it keeps giving me error

construct an small app using shiny, after i code a loop it keeps giving me error
Why am I getting this error"evaluation nested too deeply: infinite recursion / options(expressions=)?"
library(shiny)
ui<-fluidPage(
numericInput(inputId = "S0",label = "price at time 0",value = 20),
numericInput(inputId = "k",label = "exercise price",value = 20),
numericInput(inputId = "N",label = "steps",value = 50),
numericInput(inputId = "r",label = "riskfree rate",value = 0.03),
numericInput(inputId = "t",label = "time to exercise data",value = 1),
plotOutput(outputId = "v")
)
server<-function(input,output)
{
ve<-reactive({vector(mode="numeric",length=input$N+1)})
ve<-reactive({rep(input$N,9)})
for(i in 1:10)
{
ve<-reactive({c(ve(),i)})
}
output$v<-renderPlot({plot(ve())})
}
shinyApp(ui=ui,server=server)
it seems that something wrong with the for() sentence

Wow addon failing to work with array

I'm trying to create a simple addon for world of warcraft which records my kills.
I've already got'n quite far except there is a problem with the writing of a lua array.
The code I have so far
local CharacterDefaults = {
kills = {},
totalkills = 0
}
local killDefaults = {
DBtimeofday = 0,
DBplayer = 0,
DBenemyname = 0,
DBenemyid = 0,
DBzone = 0,
DBkilltype = 0
}
The next piece is inside a event which checks for overkill
if not KillCount then
KillCount = CharacterDefaults
end
if not KillCount.totalkills then
KillCount.totalkills = 0
end
KillCount.enemy[KillCount.totalkills] = destName
KillCount.kills[KillCount.totalkills] = killDefaults
KillCount.kills[KillCount.totalkills].DBtimeofday = stamp
KillCount.kills[KillCount.totalkills].DBzone = zone
KillCount.kills[KillCount.totalkills].DBkilltype = killtype
KillCount.kills[KillCount.totalkills].DBenemyid = unitId
KillCount.kills[KillCount.totalkills].DBenemyname = destName
KillCount.kills[KillCount.totalkills].DBplayer = playerName
KillCount.totalkills = KillCount.totalkills + 1
Ofcourse there's more code but this is the only important code (as far as I know).
If I look at this I would expect that for every new kill a new array part is made and the values are entered. However, for each kill I make in world of warcraft, every single item already in it will get the results of the last kill.
The lua variables saved file:
KillCount = {
["kills"] = {
{
["DBplayer"] = "MyName",
["DBzone"] = "Blackrock Depths",
["DBkilltype"] = 0,
["DBenemyname"] = "Grim Patron",
["DBenemyid"] = 9545,
["DBtimeofday"] = "11-09-22 10:45:23",
}, -- [1]
{
["DBplayer"] = "MyName",
["DBzone"] = "Blackrock Depths",
["DBkilltype"] = 0,
["DBenemyname"] = "Grim Patron",
["DBenemyid"] = 9545,
["DBtimeofday"] = "11-09-22 10:45:23",
}, -- [2]
[0] = {
["DBplayer"] = "MyName",
["DBzone"] = "Blackrock Depths",
["DBkilltype"] = 0,
["DBenemyname"] = "Grim Patron",
["DBenemyid"] = 9545,
["DBtimeofday"] = "11-09-22 10:45:23",
},
},
["totalkills"] = 3,
}
as you can see the [0] is the only one to be properly writen. Am I doing something wrong?
The problem is here:
KillCount.kills[KillCount.totalkills] = killDefaults
Everytime you kill, you're pointing KillCount.kills[KillCount.totalkills] to killDefaults then modifying killDefaults. The problem is, you are using the same killDefaults every time. So when you udpate the values of killDefaults later, it affects every reference to killDefaults that you have already created.
Try something like:
function GetDefaultKills()
return {
DBtimeofday = 0,
DBplayer = 0,
DBenemyname = 0,
DBenemyid = 0,
DBzone = 0,
DBkilltype = 0
};
end
KillCount.kills[KillCount.totalkills] = GetDefaultKills()

Resources