我刚开始学习机器学习,在练习其中一项任务时,我遇到了价值错误,但我遵循了与讲师相同的步骤。
我收到值错误,请帮忙。
天涯
Country Name
0 AUS Sri
1 USA Vignesh
2 IND Pechi
3 USA Raj
Run Code Online (Sandbox Code Playgroud)
首先我执行了标签编码,
X=dff.values
label_encoder=LabelEncoder()
X[:,0]=label_encoder.fit_transform(X[:,0])
out:
X
array([[0, 'Sri'],
[2, 'Vignesh'],
[1, 'Pechi'],
[2, 'Raj']], dtype=object)
Run Code Online (Sandbox Code Playgroud)
然后对同一个 X 进行一次热编码
onehotencoder=OneHotEncoder( categorical_features=[0])
X=onehotencoder.fit_transform(X).toarray()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
ValueError Traceback (most recent call last)
<ipython-input-472-be8c3472db63> in <module>()
----> 1 X=onehotencoder.fit_transform(X).toarray()
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py in fit_transform(self, X, y)
1900 """
1901 return _transform_selected(X, self._fit_transform,
-> 1902 self.categorical_features, copy=True)
1903
1904 def _transform(self, X):
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py in _transform_selected(X, transform, selected, copy)
1695 X : …Run Code Online (Sandbox Code Playgroud) python preprocessor scikit-learn sklearn-pandas one-hot-encoding
foo.cpp:
#define ID A
#if ID == A
#warning "hello, world"
#endif
Run Code Online (Sandbox Code Playgroud)
编译g++ -c foo.cpp工作正常:(g ++ v8.2.0)
foo.cpp:3:2: warning: #warning "hello, world" [-Wcpp]
#warning "hello, world"
^~~~~~~
Run Code Online (Sandbox Code Playgroud)
现在,如果我取代#define ID A用#define *,然后我得到:
foo.cpp:1:12: error: operator '*' has no left operand
#define ID *
^
foo.cpp:2:5: note: in expansion of macro ‘ID’
#if ID == A
^~
Run Code Online (Sandbox Code Playgroud)
有什么特别之处*?为什么它在#if表达式中失败?
当我尝试在Linux中使用G ++ 4.8编译程序时出现错误“未提供有效的预处理令牌”。并且在Solaris中使用CCSuntudio进行编译时没有错误。
在我的代码下面:
#include <iostream>
#define func(type1,varname1) \
cout << "ma var est "<<##varname1<<" et le type est "<<#type1; \
cout <<endl;
using namespace std;
int main() {
func("int", "area");
}
Run Code Online (Sandbox Code Playgroud)
它可以在CCSunStudio中完美运行,但不适用于G ++
hello.hxx:2:23: error: pasting "<<" and ""area"" does not give a valid preprocessing token
cout << "ma var est "<<##varname1<<" et le type est "<<#type1; \
^
hello.cxx:7:1: note: in expansion of macro ‘func’
func("int","area");
^
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
我正在尝试定义一个 C++ 头文件,该文件访问宏中定义的数组元素。
数组定义为:
#define NOZZLE_TO_PROBE_OFFSET { 27, 35, -1.5 }
Run Code Online (Sandbox Code Playgroud)
我试图像这样访问它,以获得第一个元素:
#define Z_STEPPER_ALIGN_XY { { NOZZLE_TO_PROBE_OFFSET[0] , Y_BED_SIZE/2 }, { X_BED_SIZE, Y_BED_SIZE/2 } }
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Marlin/src/gcode/calibrate/../../inc/../../Configuration_adv.h:659:57: error: expected '}' before '[' token
#define Z_STEPPER_ALIGN_XY { { NOZZLE_TO_PROBE_OFFSET[0] , Y_BED_SIZE/2 }, { X_BED_SIZE, Y_BED_SIZE/2 } }
~ ^
Run Code Online (Sandbox Code Playgroud)
我无法记住我的宏扩展规则,而且似乎也无法找到正确的谷歌术语来帮助解决这个问题。该消息是有道理的,但我不确定该尝试什么作为表示数组访问的替代方法。我想我想让预处理器做的是嵌入数组文字,然后是访问,这样输出就会扩展到{ 27, 35, -1.5 }[0]我很欣赏这个公认的 n00by 问题的反馈!
void testFunc();
int myval = 0;
int main()
{
int a = 1;
if (a > 0)
{
#define TEST1
testFunc();
#undef TEST1
}
int b = 2;
if ( b > 0)
{
#define TEST2
testFunc();
#undef TEST2
}
std::cout << "val : " << myval << endl;
getchar();
return 0;
}
void testFunc()
{
#ifdef TEST1
#define HERE 1
#endif
#ifdef TEST2
#define HERE 2
#endif
#ifdef HERE
myval = HERE;
#else
myval = -1;
#endif
}
Run Code Online (Sandbox Code Playgroud)
如何在第一次调用 …
是否可以连接语言之外的带引号的字符串文字(在本例中为 C++)?
也就是说,我可以这样定义MY_MACRO(a,b,c)和使用它:
MY_MACRO("one", "two", "three")
Run Code Online (Sandbox Code Playgroud)
并将其扩展为:"onetwothree"?
用例是将属性及其消息应用于函数签名,如下所示:
MY_ATTRIBUTE_MACRO("this", "is", "the reason") int foo() { return 99; }
Run Code Online (Sandbox Code Playgroud)
这将导致:
[[nodiscard("thisisthe reason")]] int foo() { return 99; }
Run Code Online (Sandbox Code Playgroud) 我正在使用 Progress-4GL 版本 11.6。
正如在另一个问题中所解释的,我现在正在使用动态查询,如下所示:
CREATE BUFFER h-Table1 FOR TABLE "Table1" NO-ERROR.
IF VALID-HANDLE(h-Table1)
...
Run Code Online (Sandbox Code Playgroud)
我已将这段代码放在一个*.i文件中,我将其包含为:
{incl\include_file.i}
Run Code Online (Sandbox Code Playgroud)
我只想将此包含文件放在某些客户的系统中。但是,这会导致其他客户出现编译问题。
有没有办法说(C 风格的预处理器):
#IF <condition>
#THEN {incl\include_file.i}
Run Code Online (Sandbox Code Playgroud)
如果是,我可以在这样的预处理器指令中使用什么条件?
提前致谢
#include<stdio.h>
#define begin(m,a,i,n) m##a##i##n
#define start begin(m,a,i,n)
void start() {
printf("Hello");
}
Run Code Online (Sandbox Code Playgroud)
是的,是的,我确实看到了这些字母,m a i n但是它们是如何组合在一起并起作用的?
调试器...似乎对这个程序没有帮助。
对我的 C++ 代码进行分析后,发现该pow函数被大量使用。
我的一些pow函数有一个整数指数和另一个非整数指数。我只对整数指数感兴趣。
为了提高性能,我正在寻找一种定义宏的方法,如下所示:
#define pow(x,n) ({\
double product;\
if (typeid(n).name() == "i") {\
for(int i = 0; i < n-1; i++)\
product *= x;}\
else\
product = pow(x,n);\
product;\
})
Run Code Online (Sandbox Code Playgroud)
但我没有得到关于运行时间的预期收益。我认为这是由于else我的宏中我称之为经典pow函数的部分所致。
如何在预处理期间“写入”宏之前提前确定指数类型?
理想情况下,我希望仅在指数是整数时应用此宏,但似乎我的尝试不相关。
根据您的建议,我尝试了三种选择:
第一个选项:只需添加重载内联函数,其基数为integeror double:
// First option
inline int pow(int x, int n){
// using simple mechanism for repeated multiplication
int product = 1;
for(int i = 0; i < n; i++){
product *= x; …Run Code Online (Sandbox Code Playgroud) 这两个不同的程序之间有性能差异吗?
#define K 50
void main() {
int k = K;
}
Run Code Online (Sandbox Code Playgroud)
void main() {
int k = 50;
}
Run Code Online (Sandbox Code Playgroud) preprocessor ×10
c++ ×6
macros ×3
c ×2
g++ ×2
gcc ×1
memory ×1
openedge ×1
optimization ×1
performance ×1
pow ×1
progress-4gl ×1
python ×1
scikit-learn ×1